The R Project SVN R

Rev

Rev 56382 | Rev 71394 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/base/man/sys.source.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2007 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
7210 hornik 6
\name{sys.source}
56186 murdoch 7
\alias{sys.source}
7210 hornik 8
\title{Parse and Evaluate Expressions from a File}
9
\description{
10
  Parses expressions in the given file, and then successively evaluates
17220 hornik 11
  them in the specified environment.
7210 hornik 12
}
8992 maechler 13
\usage{
35450 murdoch 14
sys.source(file, envir = baseenv(), chdir = FALSE,
15561 ripley 15
           keep.source = getOption("keep.source.pkgs"))
8992 maechler 16
}
7210 hornik 17
\arguments{
18
  \item{file}{a character string naming the file to be read from}
19
  \item{envir}{an \R object specifying the environment in which the
17220 hornik 20
    expressions are to be evaluated.  May also be a list or an integer.
21
    The default value \code{NULL} corresponds to evaluation in the base
22
    environment.  This is probably not what you want; you should
23
    typically supply an explicit \code{envir} argument.}
8992 maechler 24
  \item{chdir}{logical; if \code{TRUE}, the \R working directory is
8849 hornik 25
    changed to the directory containing \code{file} for evaluating.}
42961 ripley 26
  \item{keep.source}{logical.  If \code{TRUE}, functions keep
27
    their source including comments, see
25118 hornik 28
    \code{\link{options}(keep.source = *)} for more details.}
7210 hornik 29
}
30
\details{
8992 maechler 31
  For large files, \code{keep.source = FALSE} may save quite a bit of
32
  memory.
25815 jmc 33
%%FIXME:  the following paragraph should be somewhere it's likely to be seen
34
  In order for the code being evaluated to use the correct environment
35
  (for example, in global assignments), source code in packages should
56382 murdoch 36
  call \code{\link{topenv}()}, which will return the namespace, if any,
49649 ripley 37
  the environment set up by \code{sys.source}, or the global environment
25815 jmc 38
  if a saved image is being used.
7210 hornik 39
}
8992 maechler 40
\seealso{\code{\link{source}}, and \code{\link{library}} which uses
41
  \code{sys.source}.
7210 hornik 42
}
40411 ripley 43
\examples{
44236 ripley 44
## a simple way to put some objects in an environment
45
## high on the search path
40411 ripley 46
tmp <- tempfile()
47
writeLines("aaa <- pi", tmp)
48
env <- attach(NULL, name = "myenv")
49
sys.source(tmp, env)
50
unlink(tmp)
51
search()
52
aaa
53
detach("myenv")
54
}
7210 hornik 55
\keyword{file}
56
\keyword{utilities}