Title: | Read and Write Data |
---|---|
Description: | Offers a wide range of functions for reading and writing data in various file formats, including CSV, RDS, Excel and ZIP files. Additionally, it provides functions for retrieving metadata associated with files, such as file size and creation date, making it easy to manage and organize large data sets. This package is designed to simplify data import and export tasks, and provide users with a comprehensive set of tools to work with different types of data files. |
Authors: | Tomer Iwan [aut, cre, cph] |
Maintainer: | Tomer Iwan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.6.0 |
Built: | 2025-02-11 03:26:12 UTC |
Source: | https://github.com/vusaverse/vvmover |
This function adds a new column to a data frame with the current date and time. The name of the new column is a combination of the provided prefix, stage, and "Date_time". If the new column already exists, it will be overwritten.
add_current_datetime_column(data)
add_current_datetime_column(data)
data |
Data frame. |
Data frame with an additional column containing the current date and time.
## Not run: # Create a sample data frame data <- data.frame(a = 1:5, b = letters[1:5]) # Add date to file name add_current_datetime_column(data) ## End(Not run)
## Not run: # Create a sample data frame data <- data.frame(a = 1:5, b = letters[1:5]) # Add date to file name add_current_datetime_column(data) ## End(Not run)
This function calculates the percentage of NA values in a given vector. It also includes a margin of 10%.
calculate_na_percentage(x, ...)
calculate_na_percentage(x, ...)
x |
A numeric vector. |
... |
Additional arguments (not used). |
A numeric value representing the percentage of NA values in the vector.
Check if a package is installed. If not, throw an error message
check_installed_package(package_name, check = FALSE)
check_installed_package(package_name, check = FALSE)
package_name |
the name of the package (quoted) |
check |
the function should work as a boolean operator |
Boolean value whether package is installed.
check_installed_package("dplyr")
check_installed_package("dplyr")
get_last_modified_date
get_last_modifed_date(file_path)
get_last_modifed_date(file_path)
file_path |
Path to the file. |
Date that file was last modified
Is a wrapper around get_recent_file_date_filename_ymd en get_recent_file_date_modified and retrieves the most recent version of a file based on naming or date modified.
get_recent_file(path, match, date_type = "modified")
get_recent_file(path, match, date_type = "modified")
path |
The path to search for the file |
match |
The search term matched in the file name |
date_type |
The way to find the recent file date_type = "modified" is based on customization, date_type = "filename_ymd" is based on file name. |
The most recent file.
Other Get recent files:
get_recent_file_date_filename_ymd()
,
get_recent_file_date_modified()
This function determines the path of the most recent version of a file in a folder. Sorting is determined by file name where it is a condition that the filename starts with ymd encoding.
get_recent_file_date_filename_ymd(path, match)
get_recent_file_date_filename_ymd(path, match)
path |
The path to search for the file. |
match |
The search term to match in the file name. |
The most recent file
Other Get recent files:
get_recent_file_date_modified()
,
get_recent_file()
Get recent file date modified This function determines the path of the most recent version of a file in a folder. The sorting is determined based on the date of the last change.
get_recent_file_date_modified(path, match, echo = TRUE)
get_recent_file_date_modified(path, match, echo = TRUE)
path |
The path to search for the file. |
match |
The search term to match in the file name. |
echo |
Print the date the file was last modified in the console. |
The most recent file.
Other Get recent files:
get_recent_file_date_filename_ymd()
,
get_recent_file()
This function checks if a field is a subset. We define a subset as a character field that contains fewer than 20 unique values.
is_field_subset(field_name, df, column_names, column_types)
is_field_subset(field_name, df, column_names, column_types)
field_name |
Name of the field to check. |
df |
Dataframe to check. |
column_names |
Set that the field is part of. |
column_types |
Types that belong to the column names. |
Move files in a directory based on regular expression
move_files_pattern(Folder_origin, Folder_dest, pattern, recursive = FALSE)
move_files_pattern(Folder_origin, Folder_dest, pattern, recursive = FALSE)
Folder_origin |
Source folder. |
Folder_dest |
Destination folder. |
pattern |
Pattern to match files in source folder on. |
recursive |
Default: FALSE. Whether to use recursive search in directory. |
message
This function prints the date a file was last modified
print_last_modified(path)
print_last_modified(path)
path |
The file path |
message
print_last_modified(readr::readr_example("mtcars.csv"))
print_last_modified(readr::readr_example("mtcars.csv"))
Generate a random string vector
random_string_vector( n = 500, length = 6, characters = c(letters, LETTERS, 0:9) )
random_string_vector( n = 500, length = 6, characters = c(letters, LETTERS, 0:9) )
n |
The number of items in the vector. Default is set to 500. |
length |
the number of characters in a string. Default is set to 6. |
characters |
A vector containing the characters to include. Default is all lowercase, all, uppercase letters and all numbers. |
Read in all sheets in an Excel file.
read_excel_allsheets(filename)
read_excel_allsheets(filename)
filename |
Name of Excel file |
Dataframe
read_excel_allsheets(readxl::readxl_example("clippy.xls"))
read_excel_allsheets(readxl::readxl_example("clippy.xls"))
Stores session info in a .txt file.
save_session_info_to_file(path)
save_session_info_to_file(path)
path |
The directory path where the session info file will be saved. |
A .txt file containing session info, saved at the specified path.
Extract a .zip archive and read it in with readr's read_delim function. The file is extracted to a temporary location, and then deleted after reading it.
unzip_read_delim(zip_path, filename = NULL, ...)
unzip_read_delim(zip_path, filename = NULL, ...)
zip_path |
The file path of the .zip archive |
filename |
OPTIONAL: The file name of the file in the .zip archive to be read. This parameter can be left empty if there is only 1 file in the archive. |
... |
arguments to the readr::read_delim function. see: read_delim |
Dataframe
unzip_read_delim(readr::readr_example("mtcars.csv.zip"))
unzip_read_delim(readr::readr_example("mtcars.csv.zip"))