hack {mvbutils} | R Documentation |
Modify standard R functions, including tweaking their default arguments
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
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 |
where |
where to find the replacement function, defaulting to usual search path |
in.imports |
usually TRUE, if this is being called from an |
override.env |
should the replacement use its own environment, or (by default) the one that was originally there? |
Examples
## 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)