Source R files

include(
  files_andor_dirs,
  envir = parent.frame(),
  chdir = FALSE,
  recursive = FALSE
)

Arguments

files_andor_dirs

A character vector of filepaths to R files, or directories containing R files. Directories are searched for files that end with extension ".R" or ".r", ignoring those that start with a period (.) or an underscore (_). The found files files from each directory are sorted by their basename() before being sourced. Filepaths can be supplied explicitly to override the default sorting.

envir

An R environment. By default, the current R evaluation environment.

chdir

logical; if TRUE, the R working directory is changed to the directory containing file for evaluating.

recursive

whether to search directories recursively for R files.

Value

The environment envir, invisibly.

Details

This is a vectorized wrapper around base::sys.source with some differences. Notably:

  • envir defaults to the current frame

  • envir is returned (invisibly)

  • keep.source and keep.parse.data default to getOption("keep.source") and getOption("keep.parse.data") respectively, instead of getOption("keep.source.pkgs") and getOption("keep.parse.data.pkgs")

  • toplevel.env is set to getOption("topLevelEnvironment", envir). In other words, if the option topLevelEnvironment is already set, it is respected.