Last active
May 17, 2024 07:00
-
-
Save franklinokech/806142abc88388b1558b683f7f7ab137 to your computer and use it in GitHub Desktop.
R data mananagament functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load necessary package | |
library(here) | |
# Function to create a directory if it doesn't exist and include a README file | |
create_dir_if_not_exist <- function(dir_name) { | |
dir_path <- here(dir_name) | |
if (!dir.exists(dir_path)) { | |
dir.create(dir_path, recursive = TRUE) | |
message("Directory created: ", dir_path) | |
# Create README file | |
readme_path <- file.path(dir_path, "README.md") | |
writeLines("# This is the README file for the directory.", readme_path) | |
message("README file created: ", readme_path) | |
} | |
} | |
# Function to create project-wide README file | |
create_project_readme <- function() { | |
project_root <- here() | |
readme_path <- file.path(project_root, "README.md") | |
if (!file.exists(readme_path)) { | |
writeLines("# Project README", readme_path) | |
} | |
} | |
# List of directories to create | |
dirs_to_create <- c("data/raw", "data/processed", "models", "figures", "scripts", "reports") | |
# Create directories with README files | |
sapply(dirs_to_create, create_dir_if_not_exist) | |
# Create project-wide README file | |
create_project_readme() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment