R/development/project_template.R

Defines functions hello_world

hello_world <- function(path, ...) {
  # ensure path exists
  dir.create(path, recursive = TRUE, showWarnings = FALSE)

  # generate header for file
  header <- c(
    "# This file was generated by a call to 'ninjar::hello_world()'.",
    "# 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(path, "INDEX"))
}
bfatemi/ninjar documentation built on Sept. 8, 2019, 7:37 p.m.