source
Read Expressions from a File or a Connection

### Description

Parses and then evaluates each expression in the given file. By default, the evaluation is done in the current environment.

### Usage

    source(file, local = FALSE, echo = verbose, print.eval = echo,
           exprs, spaced = use_file, verbose = getOption("verbose"),
           prompt.echo = getOption("prompt"), max.deparse.length = 150,
           width.cutoff = 60L, deparseCtrl = "showAttributes",
           chdir = FALSE, encoding = getOption("encoding"),
           continue.echo = getOption("continue"), skip.echo = 0,
           keep.source = getOption("keep.source"))
    withAutoprint(exprs, evaluated = FALSE, local = parent.frame(),
           print. = TRUE, echo = TRUE, max.deparse.length = Inf,
           width.cutoff = max(20, getOption("width")),
           deparseCtrl = c("keepInteger", "showAttributes", "keepNA"),
           ...)

### Arguments

file | a connection or a character string giving the name of a file or URL. The file is parsed, and the resulting expressions are evaluated.
local | a logical value or an environment. If FALSE (the default), then the expressions are evaluated in the top (global) frame. If TRUE, then the expressions are evaluated locally to the function calling source. If an environment, then the expressions are evaluated locally to that environment.
echo | a logical value. If TRUE, then each expression is printed, along with a prompt, before it is evaluated. The default is FALSE.
print.eval | a logical value. if TRUE, then the result of each expression is printed. The default value is the same as the value specified for echo.
exprs | an expression (or an object that can be converted to an expression with as.expression). This argument can be supplied instead of file. Its default value is parse(file, keep.source=keep.source).
spaced | a logical value used when echo=TRUE. If TRUE, then print a blank line before echoing an input expression. If FALSE, then do not print such blank lines.
verbose | This argument is not yet implemented. a logical value. If TRUE, then more diagnostics are printed when parsing and evaluation.
prompt.echo | a character string. Specifies the prompt to use if echo = TRUE.
max.deparse.length | an integer. Used only when echo is TRUE. Specifies the maximal number of characters output for a single input expression. Truncated expressions are marked with a trailing "[TRUNCATED]".
width.cutoff | an integer value passed to deparse when deparse is used to format input expressions for echoing.
deparseCtrl | a character vector passed as the control argument to deparse.
chdir | a logical value. If TRUE, and if file is a pathname, then the working directory is changed temporarily to the directory containing the file to evaluate. The default is FALSE.
encoding | a character string specifying the character encoding for the input stream. Used for converting input bytes to characters. This can be any of the encodings accepted by iconv, including "native.enc". This argument is not used when the file argument is a connection, because a connection already has an associated encoding (see file).
continue.echo | a character string specifying the continuation prompt to use when echo = TRUE.
skip.echo | an integer specifying the number of comment lines at the start of the file to skip if echo = TRUE.
keep.source | a logical value. If TRUE (the default), then the file location information is stored with parsed expressions. This is used to print the source code for functions with the original formatting.
print. | withAutoprint passes its print. argument to source as print.eval.
evaluated | A logical value. If FALSE (the default), then the exprs argument to withAutoprint is passed verbatim to source. If TRUE, then withAutoprint evaluates the exprs argument before passing it to source.
... | withAutoprint passes any unrecognized arguments to source.

### Details

If echo is FALSE, then the expressions are not printed. If you still want to echo something, then use the print function in your script.
If options("keep.source") is TRUE, then the source of functions is kept so the functions can be listed exactly as input.
withAutoprint is an alternatative interface to source, with default values set to mimic the usual parse-evaluate-print loop of the command line interface to TERR.
Value
returns the value of the last evaluated expression in the file.
See Also
parse, file, print, iconv.
Examples

    fl <- tempfile()
    cat("xx<-function(x)x+1\n", file=fl)
    cat("print(1:10)\n", file=fl, append=TRUE)
    source(fl)
    # defines the function xx in the global environment,
    # and prints
    #  [1]  1  2  3  4  5  6  7  8  9 10
    source(fl, echo=TRUE)
    # also prints each expression in the file
    unlink(fl)

Package base version 6.1.5-18
Package Index