EVOLUTION-MANAGER
Edit File: sys.source.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Parse and Evaluate Expressions from a File</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for sys.source {base}"><tr><td>sys.source {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Parse and Evaluate Expressions from a File</h2> <h3>Description</h3> <p>Parses expressions in the given file, and then successively evaluates them in the specified environment. </p> <h3>Usage</h3> <pre> 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)) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>file</code></td> <td> <p>a character string naming the file to be read from</p> </td></tr> <tr valign="top"><td><code>envir</code></td> <td> <p>an <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object specifying the environment in which the expressions are to be evaluated. May also be a list or an integer. The default value <code>NULL</code> corresponds to evaluation in the base environment. This is probably not what you want; you should typically supply an explicit <code>envir</code> argument.</p> </td></tr> <tr valign="top"><td><code>chdir</code></td> <td> <p>logical; if <code>TRUE</code>, the <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> working directory is changed to the directory containing <code>file</code> for evaluating.</p> </td></tr> <tr valign="top"><td><code>keep.source</code></td> <td> <p>logical. If <code>TRUE</code>, functions keep their source including comments, see <code><a href="options.html">options</a>(keep.source = *)</code> for more details.</p> </td></tr> <tr valign="top"><td><code>keep.parse.data</code></td> <td> <p>logical. If <code>TRUE</code> and <code>keep.source</code> is also <code>TRUE</code>, functions keep parse data with their source, see <code><a href="options.html">options</a>(keep.parse.data = *)</code> for more details.</p> </td></tr> <tr valign="top"><td><code>toplevel.env</code></td> <td> <p>an <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> 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</p> </td></tr> </table> <h3>Details</h3> <p>For large files, <code>keep.source = FALSE</code> may save quite a bit of memory. Disabling only parse data via <code>keep.parse.data = FALSE</code> can already save a lot. In order for the code being evaluated to use the correct environment (for example, in global assignments), source code in packages should call <code><a href="ns-topenv.html">topenv</a>()</code>, which will return the namespace, if any, the environment set up by <code>sys.source</code>, or the global environment if a saved image is being used. </p> <h3>See Also</h3> <p><code><a href="source.html">source</a></code>, and <code><a href="library.html">library</a></code> which uses <code>sys.source</code>. </p> <h3>Examples</h3> <pre> ## 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") </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>