#' Create ReadMe.md files
#'
#' This function creates ReadMe.md in the CORRP templates for the standard
#' file structure
#'
#'@param template Which ReadMe.md files should be created? Default is all. Partial
#'matching does work.
#'@param path Where should they be created? Default is the working directory.
#'@return
#'This function creates the desired readme files. It will not overwrite the file
#'however if it does not exists. It does not return anything.
#'@keywords ReadMe ReadMe.md
#'@export
create_readme <- function(template = c('assets', 'rmds', 'raw_data',
'produced_data', 'plots', 'tables',
'reports', 'functions', 'rscripts', 'adhoc_req'),
path = getwd()){
# set which ReadMe.md files to create
template <- match.arg(template, several.ok = T)
# create list with lines for each template
readme <- list()
readme$assets <- c("# Assets ",
" ",
"This folder contains the scope of work and other relevant files (e.g data dictionary, feedback, minutes, etc). ",
" ",
"Details about the files: ",
" ",
"File | Description",
"---|---------------------------------------------------------------------",
" ",
"")
readme$plots <- c("# Plots ",
" ",
"This folder contains all the plots. ",
" ",
"Details about the files: ",
" ",
"Folder | Description",
"---|---------------------------------------------------------------------",
" ")
readme$rmds <- c("This folder contains all the rmarkdown files ",
" ",
"Details about the files in this folder:",
" ",
"File | Description",
"---|---------------------------------------------------------------------",
" ")
readme$produced_data <- c("# Produced Data ",
" ",
"Scripts that created the files in this folder: ",
" ",
"File | Script | Description",
"---|------------------|---------------------------------------------------",
" ")
readme$raw_data <- c("# Raw Data",
" ",
"Details about the files: ",
" ",
"File | Details",
"---|---------------------------------------------------------------------",
" ",
" ")
readme$tables <- c("# Tables",
" ",
"This folder contains all the tables. ",
" ",
"Details about the files: ",
" ",
"Folder | Description",
"---|---------------------------------------------------------------------",
" ",
" ")
readme$reports <- c("# Reports",
" ",
"This folder contains the reports generated by rmd files. ",
" ",
"Details about the files: ",
" ",
"File | Description",
"---|---------------------------------------------------------------------",
" ")
readme$functions <- c("# Functions",
" ",
"This folder contains R files with functions only they need to be sourced from another script. ",
" ",
"Details about the files: ",
" ",
"File | Description",
"---|---------------------------------------------------------------------",
" ")
readme$rscripts <- c("# Rscripts",
" ",
"This folder contains the scripts in R, mainly used when there is too much code to fit in a R markdown. ",
" ",
"Details about the files: ",
" ",
"File | Description",
"---|---------------------------------------------------------------------",
" ")
readme$adhoc_req <- c("# Ad-hoc requests",
" ",
"This folder contains the files (scripts, rmds, etc) that are not related to the main aims of the project. ",
" ",
"Details about the files: ",
" ",
"File | Description",
"---|---------------------------------------------------------------------",
" ")
# Function for creating the directory
createDir <- function(x){
paste0(path, '/', x)
}
createFiles <- function(x){
file.path(path, paste0(x, '/ReadMe.md'))
}
readme <- readme[template]
pathnames <- sapply(names(readme), createDir)
dir_created <- lapply(pathnames, dir.create, showWarnings = F, recursive = T)
con <- lapply(names(readme), createFiles)
doNotOverwrite <- sapply(con, file.exists)
readme <- readme[!doNotOverwrite]
con <- con[!doNotOverwrite]
files_created <- mapply(writeLines, lapply(readme, paste0, collapse = '\n'), con)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.