runscript: Run a package script

View source: R/runscript.R

runscriptR Documentation

Run a package script

Description

Run a script associated with a particular chapter

Usage

runscript(x, method = c('run', 'copy', 'view', 'show', 'dir'),
          ask = TRUE, fmt = "ch%02d.R", package = "FinTS",
          subdir = "scripts", lib.loc = NULL)

Arguments

x

an object to identify a file in package/subdir via sprintf(fmt, x).

For example, the default 'fmt' translates x = 2 into 'ch02.R'. If no 'x' is specified, a directory of options is provided.

CAUTION: Under some systems like ESS (Emacs Speaks Statistics) under Windows, pop-up menus such as produced by runscript() may not work properly.

method

One of the following:

run

run the desired script file, similar to demo or example.

copy

make a copy if the desired script file in the working directory, similar to Stangle(vignette(...)[["file"]]).

view

display the desired script file on R console but do not execute it.

show

display the desired script file using file.show

dir

return the directory showing only the location of the desired script.

Partial matching is allowed.

ask

logical: Should par(ask=TRUE) be called before graphical output happens from the script?

fmt

a format to be used with 'x' in sprintf to create the name of a file in lib.loc/package/subdir.

subdir

subdirectory of package containing a file of the name constructed via sprintf(fmt, x).

package

Name of a package with subdirectory 'subdir'.

lib.loc

NULL or character string identifying the location where ⁠system.file(subdir, package, lib.loc)⁠ will find the folder containing the file identified via sprintf(fmt, x).

Details

similar to demo or example

Value

the full path and filename, invisibly unless method == 'dir'

Author(s)

Gabor Grothendieck and Spencer Graves

See Also

demo, sprintf, system.file, package.dir, Stangle, vignette, example

Examples

## Not run: 
# provide a menu
runscript()

# run R/library/FinTS/scripts/ch01.R
runscript(1)

# same as:
runscript(1, "run")

# make a copy as 'ch01.R' in the working directory
runscript(1, 'copy')

# display on console only
runscript(1, 'view')

# display using file.show
runscript(1, 'show')

# where is it?
runscript(1, 'dir')

# run R/library/nlme/scripts/afda-ch01.R
if(require(fda))
    runscript(1, fmt = "afda-ch%02d.R", package = "fda")

## End(Not run)

FinTS documentation built on Jan. 27, 2024, 3:01 a.m.

Related to runscript in FinTS...