Create, update, and open R programs with QMS approved headers

Redit(
  ...,
  version = NULL,
  copyright_holder = NULL,
  purpose = NULL,
  input_files = NULL,
  output_files = NULL,
  backup = FALSE,
  open = rstudioapi::isAvailable()
)

Arguments

...

file paths of R, Rmd, or qmd files. Files without extensions are set to ".R". Defaults to the path of the source editor context.

version

either NULL for the current R version, or a character in the form "N.n.n" or "Nnn". Ignored with a warning for files that already have a header.

either NULL for the default Simulations Plus copyright statement, a single character defining the copyright holders and accompanying text to follow copyright mark and year, a character vector for multiple separate copyright statements, or FALSE for no copyright.

purpose, input_files, output_files

purpose, input files, and output files of R program(s) given as character vectors. The purpose will be wrapped to fit in the header. When NULL (the default), a blank section is included. When FALSE, no section is included. Ignored with a warning for files that already have a header.

backup

logical indicating whether to create backup files.

open

logical indicating whether to open files in RStudio.

Value

invisibly returns NULL.

Details

CPP's R program header documents key elements of programs including:

  • Name: The full path to the program on CPP's file system.

  • Timestamp: The timestamp and programmer of key updates to the program.

  • Copyright: Simulation Plus' standard Copyright language.

  • Purpose: What the program is designed to do.

  • Input Files: Files read by the program.

  • Output Files: Files written by the program.

Redit serves a few distinct purposes:

  • Create new R, Rmd, and qmd files with standard headers.

  • Add headers to existing files without a header.

  • Add new timestamps and program owner name to headers in existing files.

Redit does not need to be used every time a program is updated and Redit should not be used for files that are simply being opened.

If a standard header cannot be identified in an existing file, a new header will be added if possible. In some cases, an error will occur with a suggestion to update the program: For R files, update the first line so it is an R command; For Rmd files, temporarily remove all comments from the YAML.

See also

Rcopy for copying R programs, get_header_content for getting content from headers.

Examples

if (FALSE) { # \dontrun{
# Create two new R programs
Redit("file1.R", "file2.R")

# Update these programs and create a backup
Redit("file1.R", "file2.R", backup = TRUE)

# Update the timestamp of the open R program if it has a valid header.
# If there is no valid header, either a header will be added or the error
# will try to help resolve the issue
Redit()

# R Markdown works too
Redit("new-markdown.Rmd")

# Header items can be set programmatically, which is particularly useful when
# several programs are required
Redit(
  "new-file.R",
  purpose = "experiment with headers",
  input_files = c("../data/file1.csv", "..data/file1.xpt"),
  output_files = FALSE
)
} # }