| sys.source {base} | R Documentation |
Parse and Evaluate Expressions from a File
Description
Parses expressions in the given file, and then successively evaluatesthem in the specified environment.
Usage
sys.source(file, envir = baseenv(), chdir = FALSE, keep.source = getOption("keep.source.pkgs"), keep.parse.data = getOption("keep.parse.data.pkgs"), toplevel.env = as.environment(envir))Arguments
file | a character string naming the file to be read from. |
envir | anR object specifying the environment in which theexpressions are to be evaluated. May also be a list or an integer.The default |
chdir | logical; if |
keep.source | logical. If |
keep.parse.data | logical. If |
toplevel.env | anR environment to be used as top level whileevaluating the expressions. This argument is useful for frameworksrunning package tests; the default should be used in other cases. |
Details
For large files,keep.source = FALSE may save quite a bit ofmemory. Disabling only parse data viakeep.parse.data = FALSEcan already save a lot.
Note onenvir
In order for the code being evaluated to use the correct environment(for example, in global assignments), source code in packages shouldcalltopenv(), which will return the namespace, if any,the environment set up bysys.source, or the global environmentif a saved image is being used.
See Also
source, andloadNamespace whichis called fromlibrary(.) and usessys.source(.).
Examples
## a simple way to put some objects in an environment## high on the search pathtmp <- tempfile()writeLines("aaa <- pi", tmp)env <- attach(NULL, name = "myenv")sys.source(tmp, env)unlink(tmp)search()aaadetach("myenv")