FRAMverse / framrsquared

R Package interfacing with the FRAM databases
Other
2 stars 1 forks source link

initialize function #26

Closed Ty-WDFW closed 2 days ago

Ty-WDFW commented 5 days ago

@cbedwards-dfw, thoughts?

cbedwards-dfw commented 2 days ago

I like it! How would you feel about including at optional pull of .qmd template and associated style.css from snippets? I usually end up needing to track down those two snippets and add them when I'm working on proejcts. The following two lines would do that, saving the files into the scripts folder.

usethis::use_github_file("https://github.com/FRAMverse/snippets/blob/main/R/markdown-and-quarto/custom-yaml-header.Rmd", save_as = "scripts/quarto-template-header.qmd") usethis::use_github_file("https://github.com/FRAMverse/snippets/blob/main/R/markdown-and-quarto/style.css", save_as = "scripts/styl.css")

We'd need to add usethis as a dependency, and it would arguably make the function a little more fragile or add complexity I think we'd want something to handle the case when users define custom folder name vector that doesn't include scripts -- probably an if statement checking the existence of scripts folder before downloading. I'm going to see if I can mock that up.

cbedwards-dfw commented 2 days ago

#'r lifecycle::badge("experimental")`

' Initializes a FRAM project

' @param folders Vector of folders to create

' @param renv Boolean to initialize renv

' @param templates Boolean to copy quarto templates from the snippets repo

' @export

' @examples

' \dontrun{

' framrsquared::initialize_project()

' }

initialize_project <- function(folders = c('scripts', 'original_data', 'cleaned_data', 'figures', 'results'), templates = FALSE, renv = FALSE){

purrr::walk( folders, (folder) dir.create(here::here(glue::glue("{folder}"))) ) cli::cli_alert_success('Successfully initialized FRAM project')

if (renv){ cli::cli_alert_info( "Initializing {.pkg renv}, don't forget to run {.fn renv::snapshot} before saving project" ) invisible(readline('Press [Enter] to conitue...')) renv::init() }

if (templates){ cli::cli_alert_info( "Copying quarto templates from the snippets repo..." ) file.exists("scripts/"){ prefix = "scripts/" } else { prefix = "" } usethis::use_github_file("https://github.com/FRAMverse/snippets/blob/main/R/markdown-and-quarto/custom-yaml-header.Rmd", save_as = paste0(prefix, "quarto-template-header.qmd")) usethis::use_github_file("https://github.com/FRAMverse/snippets/blob/main/R/markdown-and-quarto/style.css", save_as = paste0(prefix, "style.css"))

}

}`