runExample: Run or access example files

Description Usage Arguments Value References See Also Examples

View source: R/runExample.R

Description

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.

Usage

1
runExample(what, where = , run = TRUE, ..., echo = TRUE, prompt.echo, wd)

Arguments

what

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.

where

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.

run

Should the example code be run, or only parsed, assuming it is R source code?

..., echo, prompt.echo

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.

wd

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.

Value

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.

References

Chambers, John M.(2008) Software for Data Analysis, Springer.

See Also

demoSource for a more interactive way to run a file of R code, and exampleFiles for direct access to the path of the file.

Examples

1
2
3
4
5
## Not run: 
runExample("madCall")  # run file "madCall.R"
runExample(53) # the example appearing on page 53 of the book.

## End(Not run)

SoDA documentation built on Oct. 28, 2020, 9:07 a.m.