Source R files into an attached environment
attach_source(
...,
name = as_tidy_env_name(c(...), prefix = "source:"),
recursive = FALSE,
pos = 2L,
chdir = FALSE,
warn.conflicts = TRUE,
mask.ok = NULL,
parent = .GlobalEnv
)
filepaths to R files, or paths to directories containing R files.
A string, the name for the attached environment. By default, the
name is constructed from paths supplied to ...
. If the requested name is
not on the search path, a new environment of this name is attached.
If directories are passed to ...
, whether to search them
recursively.
The position where to attach the environment, if creating a new
one. If an environment of name
already exists, pos
is ignored.
logical. if TRUE, the R working directory is temporarily changed to the directory containing the file(s) being sourced.
logical. If TRUE (the default), print warnings about
objects in the attached environment that that are masking or masked by
other objects of the same name. If the environment specified by name
is
was attached previously, then only newly defined objects are warned about.
N.B., Even though the name is warn.conflicts
, the messages about
conflicts are not warning()
s but packageStartupMessage()
s, and can be
suppressed with suppressPackageStartupMessages()
character vector of names of objects that can mask objects on
the search path without signaling a warning if warn.conflicts
is TRUE
.
The sourced R script can also define .mask.OK
in the R environment, which
has the same effect as passing it as an argument.
R environment. If an environment specified by name
is not
already attached, then the supplied R scripts are first sourced into a new
environment with the supplied parent. The default of globalenv()
enables
calling library()
in the scripts and having the subsequent
code in the scripts "see" the attached packages.
The attached environment, invisibly.