ID EN
Environment & Scope

sys.source

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Mengurai ekspresi dalam file tertentu, lalu mengevaluasinya secara berturut-turut di lingkungan yang ditentukan.

Syntax

R
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

Parameter Deskripsi
file a character string naming the file to be read from
envir an R object specifying the environment in which the expressions are to be evaluated. May also be a list or an integer. The default value NULL corresponds to evaluation in the base environment. This is probably not what you want; you should typically supply an explicit envir argument.
chdir logical; if TRUE, the R working directory is changed to the directory containing file for evaluating.
keep.source logical. If TRUE, functions keep their source including comments, see options(keep.source = *) for more details.
keep.parse.data logical. If TRUE and keep.source is also TRUE, functions keep parse data with their source, see options(keep.parse.data = *) for more details.
toplevel.env an R environment to be used as top level while evaluating the expressions. This argument is useful for frameworks running package tests; the default should be used in other cases

Details

Untuk file berukuran besar, keep.source = FALSE mungkin menghemat cukup banyak memori. Menonaktifkan hanya parse data melalui keep.parse.data = FALSE sudah bisa menghemat banyak. Agar kode yang dievaluasi menggunakan lingkungan yang benar (misalnya, dalam penugasan global), kode sumber dalam paket harus memanggil topenv(), yang akan mengembalikan namespace, jika ada, lingkungan yang diatur oleh sys.source, atau lingkungan global jika gambar yang disimpan sedang digunakan.

Contoh

Example
R
# NOT RUN {
## 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")
# }

See Also

source and library which uses sys.source.