[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  source: Read R Code from a File, a Connection or Expressions

##  Description

` source ` causes  R  to accept its input from the named file or URL or
connection or expressions directly. Input is read and ` [ parse
](/link/parse?package=base&version=3.6.2) ` d from that file until the end of
the file is reached, then the parsed expressions are evaluated sequentially in
the chosen environment.

` withAutoprint(exprs) ` is a wrapper for ` source(exprs = exprs, ..) ` with
different defaults. Its main purpose is to evaluate and auto-print expressions
as if in a toplevel context, e.g, as in the  R  console.

##  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 ](/link/connection?package=base&version=3.6.2) or a character
string giving the pathname of the file or URL to read from. ` "" ` indicates
the connection ` [ stdin ](/link/stdin?package=base&version=3.6.2) () ` .

local

` TRUE ` , ` FALSE ` or an environment, determining where the parsed
expressions are evaluated. ` FALSE ` (the default) corresponds to the user's
workspace (the global environment) and ` TRUE ` to the environment from which
` source ` is called.

echo

logical; if ` TRUE ` , each expression is printed after parsing, before
evaluation.

print.eval, print.

logical; if ` TRUE ` , the result of ` eval(i) ` is printed for each
expression ` i ` ; defaults to the value of ` echo ` .

exprs

for ` source() ` and ` withAutoprint(*, evaluated=TRUE) ` : _instead_ of
specifying ` file ` , an ` [ expression
](/link/expression?package=base&version=3.6.2) ` , ` [ call
](/link/call?package=base&version=3.6.2) ` , or ` [ list
](/link/list?package=base&version=3.6.2) ` of ` [ call
](/link/call?package=base&version=3.6.2) ` 's, but _not_ an unevaluated
“expression”.

for ` withAutoprint() ` (with default ` evaluated=FALSE ` ): one or more
unevaluated “expressions”.

evaluated

logical indicating that ` exprs ` is passed to ` source(exprs= *) ` and hence
must be evaluated, i.e., a formal ` expression ` , ` call ` or ` list ` of
calls.

spaced

logical indicating if newline (hence empty line) should be printed before each
expression (when ` echo = TRUE ` ).

verbose

if ` TRUE ` , more diagnostics (than just ` echo = TRUE ` ) are printed during
parsing and evaluation of input, including extra info for **each** expression.

prompt.echo

character; gives the prompt to be used if ` echo = TRUE ` .

max.deparse.length

integer; is used only if ` echo ` is ` TRUE ` and gives the maximal number of
characters output for the deparse of a single expression.

width.cutoff

integer, passed to ` [ deparse ](/link/deparse?package=base&version=3.6.2) ()
` which is used (only) when there are no source references.

deparseCtrl

` [ character ](/link/character?package=base&version=3.6.2) ` vector, passed
as ` control ` to ` [ deparse ](/link/deparse?package=base&version=3.6.2) () `
, see also ` [ .deparseOpts ](/link/.deparseOpts?package=base&version=3.6.2) `
. In  R  version <= 3.3.x, this was ha