
Last chance! 50% off unlimited learning
Sale ends in
sys.source(file, envir = baseenv(), chdir = FALSE, keep.source = getOption("keep.source.pkgs"))
NULL
corresponds to evaluation in the base
environment. This is probably not what you want; you should
typically supply an explicit envir
argument.TRUE
, the R working directory is
changed to the directory containing file
for evaluating.TRUE
, functions keep
their source including comments, see
options(keep.source = *)
for more details.keep.source = FALSE
may save quite a bit of
memory. In order for the code being evaluated to use the correct environment
(for example, in global assignments), source code in packages should
call topenv()
, which will return the namespace, if any,
the environment set up by sys.source
, or the global environment
if a saved image is being used.
source
, and library
which uses
sys.source
.
## a simple way to put some objects in an environment
## high on the search path
tmp <- tempfile()
writeLines("aaa <- pi", tmp)
env <- attach(NULL, name = "myenv")
sys.source(tmp, env)
unlink(tmp)
search()
aaa
detach("myenv")
Run the code above in your browser using DataLab