demoSource: Flexible execution of R source for demonstrations

Description Usage Arguments Details Value See Also

View source: R/demoSource.R

Description

R expressions in a source file are shown and evaluated sequentially, in an R “demo” session. Lines are alternately shown and evaluated when the user types empty lines to the function demoInput in another R session (the “input” session) running in the same working directory. Any R expression typed in the input session is shown and evaluated in the demo, allowing you to add to the canned demo.

Usage

1
2
3
4
demoSource(demo=, inputCon,  where = .GlobalEnv)
demoInput(path=)

demoExample(name, package = "SoDA")

Arguments

demo

Either the file name or input connection for the R source to be demonstrated, or an object from class "demoSource". The latter allows resuming a demo.

By default, a menu interface prompts the user to select an R source file in the local directory or type in a path string (see localRFiles

inputCon

The connection from which to read prompt input. Usually omitted in which case a call to demoInput() should occur in another R session in the same directory (see the details).

where

The environment where the demo expressions should be evaluated. By default, in the global environment.

path

The file system path where user input is passed to the demo controller. Must be a writable location and be known to both R sessions. Usually omitted, in which case a suitable fifo is created to communicate with demoSource().

name

For demoExample(), the name of the example file, with or without a ".R" suffix. There should be a corresponding file in the "Examples" subdirectory of the package.

Once the file has been determined, demoExample just calls demoSource.

package

The name of the package to use to find the example file.

Details

The demo is begun by starting R twice in two separate shell (terminal) windows, in the same working directory, the input window and the demo window. To start the demo, the user calls demoInput in the input window, with no arguments. The call to demoInput goes into a loop reading terminal input.

In the demo window, the user then calls demoSource, usually just supplying the file name for the source file. The input process now reads lines from the terminal and writes to a fifo that will be read by the demo process. Empty lines (the usual) alternately display and evaluate single lines from the source file. A line consisting only of a comma is a continuation: The next line of the source is read and displayed but not yet evaluated. Use this mechanism to collect a bunch of lines to be evaluated together, such as a function definition. When the last line of the bunch is displayed, enter an empty line to evaluate all the lines at once.

A line containing only q quits from demoInput, which you need to do before starting to run another demo. Quitting from the input also causes the quit command to be written to the fifo, at which point demoSource returns the current state of the demo. If you quit before the demo is finished, and you have arranged to assign the returned value from demoSource, that object can be supplied in a subsequent call to demoSource to resume this demo.

Any input other than an empty line, comma or q is interpreted as a literal expression that the user wants evaluated instead of the next source line.

Source lines in the demo file ending in "#SILENT" will be silently executed before the next ordinary line is displayed.

Value

demoSource() and demoExample() return, invisibly, the "demoSource" object describing the current state of the demo.

See Also

demoSource-class()


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