hack: Modify standard R functions, including tweaking their default...

Description Usage Arguments Examples

Description

You probably shouldn't use these... hack lets you easily change the argument defaults of a function. assign.to.base replaces a function in base or utils (or any other package and its namespace and S3 methods table) with a modified version, possibly produced by hack. Package mvbutils uses these two to change the default position for library attachment, etc; see the code of mvbutils:::.onLoad.

Note that, if you call assign.to.base during the .onLoad of your package, then it must be called directly from the .onLoad, not via an intermediate function; otherwise, it won't correctly reset its argument in the import-environment of your namespace. To get round this, wrap it in an mlocal; see mvbutils:::.onLoad for an example.

assign.to.base is only meant for changing things in packages, e.g. not for things that merely sit in non-package environments high on the search path (where <<- should work). I don't know how it will behave if you try. It won't work for S4 methods, either.

Usage

1
2
 hack( fun, ...)
 assign.to.base( x, what=,  where=-1, in.imports=, override.env = TRUE)

Arguments

fun

a function (not a character string)

...

pairlist of arguments and new default values, e.g. arg1=1+2. Things on RHS of equal signs will not be evaluated.

x

function name (a character string)

what

function to replace x, defaulting to "replacement." %&% x

where

where to find the replacement function, defaulting to usual search path

in.imports

usually TRUE, if this is being called from an .onLoad method in a namespace. Make sure any copies of the function to be changed that are in the "imports" namespace also get changed. See Description.

override.env

should the replacement use its own environment, or (by default) the one that was originally there?

Examples

1
2
3
4
5
## Not run: 
hack( dir, all.files=getOption( "ls.all.files", TRUE)) # from my '.First'
assign.to.base( "dir", hack( dir, all.files=TRUE))

## End(Not run)

Example output

Attaching package: 'mvbutils'

The following object is masked from 'package:graphics':

    clip

The following objects are masked from 'package:utils':

    ?, help

The following objects are masked from 'package:base':

    print.default, print.function, rbind, rbind.data.frame

function (path = ".", pattern = NULL, all.files = getOption("ls.all.files", 
    TRUE), full.names = FALSE, recursive = FALSE, ignore.case = FALSE, 
    include.dirs = FALSE, no.. = FALSE) 
.Internal(list.files(path, pattern, all.files, full.names, recursive, 
    ignore.case, include.dirs, no..))
<environment: namespace:base>

mvbutils documentation built on May 2, 2019, 8:32 a.m.

Related to hack in mvbutils...