-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: CSV export #40
Comments
Here is a possible solution to this issue. #' Save Datasets from an R Package
#'
#' The save_datasets function saves all datasets in a specified R package, saving them as CSV files in a specified folder.
#'
#' @param package_name The name of the R package containing the datasets to be saved. The default value is "datasauRus".
#' @param folder_name The name of the folder where the CSV files will be saved. The default value is "datasaurus_dozen_datasets".
#'
#' @return The save_datasets function doesn't return anything.
#' @export
save_datasets <- function(package_name="datasauRus", folder_name="datasaurus_dozen_datasets") {
# Get a list of all datasets in the package
datasets <- data(package = package_name)
# Create the specified folder in the current working directory, if it doesn't already exist
if (!dir.exists(folder_name)) {
dir.create(folder_name)
}
# Loop through each dataset
for ( dataset in datasets$results[, "Item"] ) {
# Write the dataset to a csv file in the specified folder
write.csv(get(dataset), file = paste0(folder_name, "/", dataset, ".csv"))
}
} This function is package ready, with all documentation. Note that we are able to set default arguments for Next iteration on this function could provide an option to save the datasets in different formats, such as in Excel and/or RDA format. |
It could be nice to have the ability to export a CSV of the datasaurus data from the R package itself
The text was updated successfully, but these errors were encountered: