R/project_template_VA.R

Defines functions project_template_VA

Documented in project_template_VA

#' create a project_template
#'
#' @param project_path Folder where project will be located
#' @param ... parameters passed through to other functions
#'
#' @export
#'

project_template_VA <- function(project_path, ...) {
    # ensure path exists
    dir.create(project_path, recursive = TRUE, showWarnings = FALSE)
    
    # generate header for file
    header <- c(
        "# This file was generated by a call to 'RPamisc::project_template_VA()'.",
        "# The following inputs were received:",
        ""
    )
    
    # collect inputs and paste together as 'Parameter: Value'
    dots <- list(...)
    text <- lapply(seq_along(dots), function(i) {
        key <- names(dots)[[i]]
        val <- dots[[i]]
        paste0(key, ": ", val)
    })
    
    # collect into single text string
    contents <- paste(
        paste(header, collapse = "\n"),
        paste(text, collapse = "\n"),
        sep = "\n"
    )
    
    # write to index file
    writeLines(contents, con = file.path(project_path, "INDEX"))
    
    
    ## VA Project structure
    # create folders
    fs::dir_create(fs::path(project_path, "Data"))
    fs::dir_create(fs::path(project_path, "Data", "RawData"))
    fs::dir_create(fs::path(project_path, "Data", "FinalData"))
    fs::dir_create(fs::path(project_path, "Pipelines"))
    fs::dir_create(fs::path(project_path, "R"))
    fs::dir_create(fs::path(project_path, "Reports"))
    fs::dir_create(fs::path(project_path, "Resources"))
    fs::dir_create(fs::path(project_path, "SQL"))
      
    
    # files to copy 
    fs::file_create(fs::path(project_path, "Data",".keep"))
    fs::file_create(fs::path(project_path, "Data", "RawData", ".keep"))
    fs::file_create(fs::path(project_path, "Data", "FinalData", ".keep"))
    fs::file_create(fs::path(project_path, "Pipelines",".keep"))
    fs::file_create(fs::path(project_path, "R",".keep"))
    fs::file_create(fs::path(project_path, "Reports",".keep"))
    fs::file_create(fs::path(project_path, "Resources",".keep"))
    fs::file_create(fs::path(project_path, "SQL",".keep"))
    
    fs::file_copy(fs::path_package("RPamisc", "rstudio", "templates", "project", "README.md"), project_path)
    fs::file_copy(fs::path_package("RPamisc", "rstudio", "templates", "project", "Data", "README.md"), project_path)
    fs::file_copy(fs::path_package("RPamisc", "rstudio", "templates", "project", ".gitignore"), project_path)
   
}
rparrish/RPamisc documentation built on Feb. 28, 2024, 9:26 p.m.