#' Create a new ENR project.
#'
#' This function will create all of the scaffolding for a new ENR project.
#' It will set up all of the relevant directories and their initial
#' contents.
#'
#' @param project_name A character vector containing the name for this new
#' project. Must be a valid directory name for your file system.
#'
#' @export
#'
#' @examples
#'
#' \dontrun{create_enr_project('new_enr_project')}
#'
create_enr_project <- function(project_name = 'enr_project'){
if (is_dir(project_name)) {
create_project_existing(project_name)
} else
create_project_new(project_name)
invisible(NULL)
}
create_project_existing <- function(project_name) {
template_path <- system.file('project_skeleton/', package = 'ENRanalytics')
template_files <- list_files_and_dirs(path = template_path)
project_path <- file.path(project_name)
file.copy(file.path(template_path, template_files),
project_path,
recursive = TRUE, overwrite = FALSE)
}
create_enr_project_new <- function(project_name) {
if (file.exists(project_name)) {
stop(paste("Cannot run create_enr_project() from a directory containing", project_name))
}
dir.create(project_name)
tryCatch(
create_project_existing(project_name = project_name),
error = function(e) {
unlink(project_name, recursive = TRUE)
stop(e)
}
)
}
list_files_and_dirs <- function(path) {
files <- list.files(path = path, all.files = TRUE, include.dirs = TRUE)
files <- grep("^[.][.]?$", files, value = TRUE, invert = TRUE)
files
}
is_dir <- function(path) {
file.exists(path) && file.info(path)$isdir
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.