Movatterモバイル変換


[0]ホーム

URL:


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 defaultbaseenv() corresponds to evaluation in the baseenvironment. This is probably not what you want; you shouldtypically supply an explicitenvir argument, see the‘Note’.

chdir

logical; ifTRUE, theR working directory ischanged to the directory containingfile for evaluating.

keep.source

logical. IfTRUE, functions keeptheir source including comments, seeoptions(keep.source = *) for more details.

keep.parse.data

logical. IfTRUE andkeep.source isalsoTRUE, functions keep parse data with their source, seeoptions(keep.parse.data = *) for more details.

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")

[Packagebase version 4.6.0Index]

[8]ページ先頭

©2009-2025 Movatter.jp