checkFiles: Checks whether all specified files are valid R or Python...

View source: R/Rsolo.R

checkFilesR Documentation

Checks whether all specified files are valid R or Python files

Description

checkFiles verifies whether all specified files are valid source files that can be executed independently of each other. If an error occurs, the following actions are taken:

  1. If open is either a function name or a function with a file parameter, then checkFiles will attempt to open the faulty source file; otherwise, it will not.

  2. The execution of checkFiles is stopped.

If you do not want the faulty source file to be opened immediately, use open=0.

Three modes are available for checking a file:

  1. exist: Does the source file exist?

  2. parse: (default) Is parse(file) (in R) or ⁠python -m py_compile "file"⁠ (in Python) successful?

  3. run: Is ⁠Rscript "file"⁠ (in R) or reticulate::py_run_file(file) (in Python) successful?

If source files have side effects, e.g., generating an image or producing other outputs, and mode == "parse", these side effects will occur during the check. To prevent a script from being executed during the check, add a ⁠## Not check:⁠ comment at the top of the script.

Usage

checkFiles(
  files,
  index = seq_along(files),
  path = NULL,
  open = openFile,
  mode = c("parse", "run", "exist"),
  ...
)

Rsolo(
  files,
  index = seq_along(files),
  path = NULL,
  open = openFile,
  mode = c("parse", "run", "exist"),
  ...
)

Arguments

files

character: file name(s)

index

integer(s): if length(index)==1 the files from index to length(files) are checked (default: seq_along(files)) otherwise the files with values in index are checked.

path

character: path to start from (default: getwd())

open

function: function or function name to call after an error occurs (default: openFile)

mode

character which check to do

...

further parameters given to the function in open

Value

nothing

Examples

if (interactive()) {
  files <- list.files(pattern="*.(R|py)$", full.names=TRUE, recursive=TRUE)
  checkFiles(files)
}

sigbertklinke/mmstat4 documentation built on Sept. 13, 2024, 4:46 p.m.