Parse and Evaluate S-PLUS Expressions from a File

DESCRIPTION:

Parses and then evaluates each expression in the given file. By default, the evaluation is done in the global frame (frame 1).

USAGE:

source(file, local=F, echo=<<see below>>, n = -1, 
       immediate = NULL) 
Splus < file

REQUIRED ARGUMENTS:

file
character string giving the name of a file or connection. The file will be parsed and the resulting expressions evaluated.

OPTIONAL ARGUMENTS:

local
a logical value; if FALSE, the expressions will be evaluated in the top (global) frame; otherwise, locally to the function calling source.
echo
if TRUE, each expression will be printed, along with a prompt, before it is evaluated. The default is TRUE if options(echo=T) has been set and length(recordConnection())==0.
n
number of expressions to read from file. If negative (the default), parsing continues to the end of the file.
immediate
The immediate argument is provided for backward compatibility only; it is no longer used.

VALUE:

the value of the last evaluated expression in the file (see eval). Automatic printing of this result is turned off, if source is called at the top level.

SIDE EFFECTS:

the working directory is changed if local=FALSE and assignments are contained in the file. Other side effects (such as plots) will be produced if present in the file.

DETAILS:

Usually, no assignments are committed until source exits normally; this means that if S-PLUS encounters an error in the source file, no assignments will be made. In the Splus < file form, each expression in the file is a top-level expression and assignments are committed expression by expression.

Large source files are rather inefficient. You may be able to write a function to do the same thing more efficiently.

NOTE:

If the last expression in the file given to source is a replacement expression (e.g., x[1]<-1 or dim(x)[1]<-2) then source returns no useful value.

SEE ALSO:

, AUDIT, , , , .

EXAMPLES:

postscript() # start a graphics device 
source("myplot") # source a file with tested plot commands