This function finds and runs a file, usually of R code. The function is specialized to look for examples included in the package and based on material in Software for Data Analysis, but can be used for other directories containing source files as well.
runExample(what, where = , run = TRUE, ..., echo = TRUE, prompt.echo, wd)
Identifies the example to be run. Can be either a character string name of the file to be run,
possibly without the suffix or the page in Software for
Data Analysis where the example appears. See
exampleFiles
for details.
The character string name of the package or directory
in which the files are to be found. By
default, and usually, it is
the SoDA
package. If a package name is given, that
package must have an "Examples"
directory.
Should the example code be run, or only parsed, assuming it is R source code?
Any optional arguments to the source
function, assuming run
is TRUE
. The default for
prompt.echo
is constructed from an abbreviation of the
file name.
The working directory in which to run the example. If the
argument is missing and where
is a package, the working
directory is the package directory, which is also the parent
directory of the Examples
directory.
If where
is a directory and not a package, and wd
is missing, then the working directory is not changed.
Otherwise, the working directory is set before running the
example and reset after. As you would hope, this argument is
ignored if run
is FALSE
.
If the file is an R source file, the function returns either the
value from source
or the parsed version of the file,
according to whether run
is TRUE
.
For non-R files, the value is currently just the character vector containing the lines of the file. Future versions may be a little more clever.
Chambers, John M.(2008) Software for Data Analysis, Springer.
demoSource
for a more interactive way to run a
file of R code, and exampleFiles
for direct access to
the path of the file.
# NOT RUN {
runExample("madCall") # run file "madCall.R"
runExample(53) # the example appearing on page 53 of the book.
# }
Run the code above in your browser using DataLab