| Line 78... |
Line 78... |
| 78 |
(as used on classic Mac OS) and map this to newline. The final line
|
78 |
(as used on classic Mac OS) and map this to newline. The final line
|
| 79 |
can be incomplete, that is missing the final end-of-line marker.
|
79 |
can be incomplete, that is missing the final end-of-line marker.
|
| 80 |
|
80 |
|
| 81 |
If \code{keep.source} is true (the default in interactive use), the
|
81 |
If \code{keep.source} is true (the default in interactive use), the
|
| 82 |
source of functions is kept so they can be listed exactly as input.
|
82 |
source of functions is kept so they can be listed exactly as input.
|
| 83 |
|
83 |
|
| 84 |
% Using \code{echo = TRUE} and \code{keep.source = TRUE} may interact
|
84 |
% Using \code{echo = TRUE} and \code{keep.source = TRUE} may interact
|
| 85 |
% badly with source code that includes \samp{#line nn "filename"}
|
85 |
% badly with source code that includes \samp{#line nn "filename"}
|
| 86 |
% directives (e.g. code produced by older versions of
|
86 |
% directives (e.g. code produced by older versions of
|
| 87 |
% \code{\link{Stangle}()}): \code{source()} will attempt to obtain the
|
87 |
% \code{\link{Stangle}()}): \code{source()} will attempt to obtain the
|
| 88 |
% source from the named file which may have changed since the code was
|
88 |
% source from the named file which may have changed since the code was
|
| 89 |
% produced. Use \code{keep.source = FALSE} to avoid this.
|
89 |
% produced. Use \code{keep.source = FALSE} to avoid this.
|
| 90 |
|
90 |
|
| 91 |
Unlike input from a console, lines in the file or on a connection can
|
91 |
Unlike input from a console, lines in the file or on a connection can
|
| 92 |
contain an unlimited number of characters.
|
92 |
contain an unlimited number of characters.
|
| 93 |
|
93 |
|
| 94 |
When \code{skip.echo > 0}, that many comment lines at the start of
|
94 |
When \code{skip.echo > 0}, that many comment lines at the start of
|
| 95 |
the file will not be echoed. This does not affect the execution of
|
95 |
the file will not be echoed. This does not affect the execution of
|
| 96 |
the code at all. If there are executable lines within the first
|
96 |
the code at all. If there are executable lines within the first
|
| 97 |
\code{skip.echo} lines, echoing will start with the first of them.
|
97 |
\code{skip.echo} lines, echoing will start with the first of them.
|
| 98 |
|
98 |
|
| 99 |
If \code{echo} is true and a deparsed expression exceeds
|
99 |
If \code{echo} is true and a deparsed expression exceeds
|
| 100 |
\code{max.deparse.length}, that many characters are output followed by
|
100 |
\code{max.deparse.length}, that many characters are output followed by
|
| 101 |
\code{ .... [TRUNCATED] }.
|
101 |
\code{ .... [TRUNCATED] }.
|
| 102 |
}
|
102 |
}
|
| 103 |
\section{Encodings}{
|
103 |
\section{Encodings}{
|
| 104 |
By default the input is read and parsed in the current encoding of
|
104 |
By default the input is read and parsed in the current encoding of
|
| 105 |
the \R session. This is usually what it required, but occasionally
|
105 |
the \R session. This is usually what it required, but occasionally
|
| 106 |
re-encoding is needed, e.g. if a file from a UTF-8-using system is to
|
106 |
re-encoding is needed, e.g. if a file from a UTF-8-using system is to
|
| 107 |
be read on Windows (or \emph{vice versa}).
|
107 |
be read on Windows (or \emph{vice versa}).
|
| 108 |
|
108 |
|
| 109 |
The rest of this paragraph applies if \code{file} is an actual
|
109 |
The rest of this paragraph applies if \code{file} is an actual
|
| 110 |
filename or URL (and not \code{""} nor a connection). If
|
110 |
filename or URL (and not \code{""} nor a connection). If
|
| 111 |
\code{encoding = "unknown"}, an attempt is made to guess the encoding:
|
111 |
\code{encoding = "unknown"}, an attempt is made to guess the encoding:
|
| 112 |
the result of \code{\link{localeToCharset}()} is used as a guide. If
|
112 |
the result of \code{\link{localeToCharset}()} is used as a guide. If
|
| 113 |
\code{encoding} has two or more elements, they are tried in turn until
|
113 |
\code{encoding} has two or more elements, they are tried in turn until
|
| 114 |
the file/URL can be read without error in the trial encoding. If an
|
114 |
the file/URL can be read without error in the trial encoding. If an
|
| 115 |
actual \code{encoding} is specified (rather than the default or
|
115 |
actual \code{encoding} is specified (rather than the default or
|
| 116 |
\code{"unknown"}) in a Latin-1 or UTF-8 locale then character strings
|
116 |
\code{"unknown"}) in a Latin-1 or UTF-8 locale then character strings
|
| 117 |
in the result will be translated to the current encoding and marked as
|
117 |
in the result will be translated to the current encoding and marked as
|
| 118 |
such (see \code{\link{Encoding}}).
|
118 |
such (see \code{\link{Encoding}}).
|
| 119 |
|
119 |
|
| 120 |
If \code{file} is a connection (including one specified by \code{""},
|
120 |
If \code{file} is a connection (including one specified by \code{""},
|
| 121 |
it is not possible to re-encode the input inside \code{source}, and so
|
121 |
it is not possible to re-encode the input inside \code{source}, and so
|
| 122 |
the \code{encoding} argument is just used to mark character strings in the
|
122 |
the \code{encoding} argument is just used to mark character strings in the
|
| 123 |
parsed input in Latin-1 and UTF-8 locales: see \code{\link{parse}}.
|
123 |
parsed input in Latin-1 and UTF-8 locales: see \code{\link{parse}}.
|
| 124 |
}
|
124 |
}
|
| Line 132... |
Line 132... |
| 132 |
\code{\link{eval}}, \code{\link{parse}} and \code{\link{scan}};
|
132 |
\code{\link{eval}}, \code{\link{parse}} and \code{\link{scan}};
|
| 133 |
\code{\link{options}("keep.source")}.
|
133 |
\code{\link{options}("keep.source")}.
|
| 134 |
|
134 |
|
| 135 |
\code{\link{sys.source}} which is a streamlined version to source a
|
135 |
\code{\link{sys.source}} which is a streamlined version to source a
|
| 136 |
file into an environment.
|
136 |
file into an environment.
|
| 137 |
|
137 |
|
| 138 |
\sQuote{The R Language Definition} for a discussion of source
|
138 |
\sQuote{The R Language Definition} for a discussion of source
|
| 139 |
directives.
|
139 |
directives.
|
| 140 |
}
|
140 |
}
|
| 141 |
\examples{
|
141 |
\examples{
|
| 142 |
## If you want to source() a bunch of files, something like
|
142 |
## If you want to source() a bunch of files, something like
|
| 143 |
## the following may be useful:
|
143 |
## the following may be useful:
|
| 144 |
sourceDir <- function(path, trace = TRUE, ...) {
|
144 |
sourceDir <- function(path, trace = TRUE, ...) {
|
| 145 |
for (nm in list.files(path, pattern = "[.][RrSsQq]$")) {
|
145 |
for (nm in list.files(path, pattern = "[.][RrSsQq]$")) {
|
| 146 |
if(trace) cat(nm,":")
|
146 |
if(trace) cat(nm,":")
|
| 147 |
source(file.path(path, nm), ...)
|
147 |
source(file.path(path, nm), ...)
|
| 148 |
if(trace) cat("\n")
|
148 |
if(trace) cat("\n")
|
| 149 |
}
|
149 |
}
|
| 150 |
}
|
150 |
}
|
| 151 |
}
|
151 |
}
|