swap_code: Preprocess R files

Description Usage Arguments Details Value See Also Examples

View source: R/package.R

Description

Preprocess R code files using a simple swapping algorithm. Files are modified in-place, hence this is potentially dangerous and should best be applied if the package directory to document, check and/or install is not the one in which coding is done but a copy of it.

Usage

1
2
3
4
  swap_code(x, ...)

  ## S3 method for class 'character'
 swap_code(x, ..., ignore = NULL)

Arguments

x

Character vector of names of input files, or names of R package directories. The latter will be expanded as appropriate. x is passed to pkg_files with the ‘installed’ argument set to FALSE. See there for further details.

...

Optional arguments, currently passed as args arguments to run_ruby. See there for details. The sole exception is an sargs argument, which is a character vector of options passed to the Ruby script. See below.

ignore

NULL or character vector with names of R code files to ignore. Passed to pkg_files, see there for details of how names are matched.

Details

The code preprocessing works simply as follows: Lines are split at the first occurrence of ‘#||’, if any, the parts reversed and joined again with a space character, including the separator. Leading whitespace is kept. Whitespace around the parts, if any, is removed (effectively transformed to a single space). There is no check done to ensure that the part moved in front of the comment character is syntactically valid in its context, or correct or useful code. For instance, the line SEALED <- FALSE #|| SEALED <- TRUE would be modified to SEALED <- TRUE #|| SEALED <- FALSE, i.e. this could be used to change a package constant before conducting any checking. Note, however, that lines starting with a roxygen2 comment will not be modified.

This preprocessing is currently implemented in a Ruby script that comes with the package. It is automatically found in the installation directory but fails if a suitable version of Ruby, i.e. ≥ 1.9.0, is unavailable. See run_ruby for details.

Value

Currently the return value of the call to run_ruby.

See Also

Other package-functions: check_R_code, check_Sweave_start, copy_pkg_files, delete_o_files, is_pkg_dir, logfile, pack_desc, pkg_files, run_R_CMD,

Examples

1
# See the 'docu.R' script provided with the package, option '--preprocess'.

pkgutils documentation built on May 2, 2019, 5:49 p.m.

Related to swap_code in pkgutils...