R/proj_setup.R

Defines functions proj_setup

proj_setup <- function(path, ...) {

  # Create directories
  dir.create(path, recursive = TRUE, showWarnings = FALSE)
  dir.create(paste0(path, "/Data"), recursive = TRUE, showWarnings = FALSE)
  dir.create(paste0(path, "/Data/Raw"), recursive = TRUE, showWarnings = FALSE)
  dir.create(paste0(path, "/Data/Processed"), recursive = TRUE, showWarnings = FALSE)
  dir.create(paste0(path, "/Analysis"), recursive = TRUE, showWarnings = FALSE)
  dir.create(paste0(path, "/Documentation"), recursive = TRUE, showWarnings = FALSE)
  dir.create(paste0(path, "/Reports"), recursive = TRUE, showWarnings = FALSE)
  dir.create(paste0(path, "/Figures"), recursive = TRUE, showWarnings = FALSE)

  # create some header text
  header <- c(
    "# GL Management Unit Project",
    "*project template generated by* `GLReportR`"
  )

  FolderDescrip <- c(
  "File | Description",
  "---------- | --------------------------------------------------",
  "Data | contains the project data in subdirectories",
  "Data/Raw | Raw data as collected should be stored here. If applicable, this data should match paper copies",
  "Data/Processed | Data that has been cleaned and mapped to the template data base",
  "Analysis | Analysis and data scrubbing scripts",
  "Documentation | Project documentation files such as survey protocols and data management plan",
  "Reports | Markdown report files or other file formats used to report on the project",
  "Figures | Saved figures to be uploaded to Project Tracker or for inclusion in Rmarkdown reports",
  "<hr />",
  "<br />"
  )

  instructions <- c(
    "# GL Managment Unit Project Template Intructions",
    "<!-- This file is best viewed using the RStudio previewer -->",
    "## Create Standard Templates",
    "Run `GLReportR::create_project_markdown_files()` to finish setup",
    "  ",
    "  ",
    "## Folder Description and Contents",
    FolderDescrip,
    "  ",
    "  ",
    "# Templates",
    "The following custom markdown templates can be accessed by selecting New Markdown > From Template",
    "<br />",
    "- Project Summary Report <br />",
    "- Project Dashboard <br />",
    "<hr />",
    "<br />",
    '<p style="text-align: center;"> *This file can be deleted following project set up.*</p>'
  )

  writeLines(instructions, con = file.path(path, "Instructions.md"))

  # 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, "<br />")
  })

    myinputs <- lapply(seq_along(dots), function(i) {
      key <- names(dots)[[i]]
      val <- dots[[i]]
      val
    })

    names(myinputs) <- c("PI", "PRJ_CD", "GLMU", "GR", "PRJ_DATE0", "PRJ_DATE1")

  # collect into single text string
  contents <- paste(
    paste(header, collapse = "\n"),
    paste(text, collapse = "\n"),
    sep = "  \n"
  )

  abstract <- c(
    "# Abstract",
    " ",
    "Please provide a simple description of the project"
    )

  # write to index file
  readme <- c(contents, " ", abstract, " ", "# Folder Description", " ", FolderDescrip)
  writeLines(readme, con = file.path(path, "ReadMe.md"))
  save(myinputs, file = file.path(path, "params.RData"))
}
HoldenJe/GLReportR documentation built on April 26, 2023, 10:22 a.m.