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.
hack( fun, ...)
assign.to.base( x, what=, where=-1, in.imports=, override.env = TRUE)
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.
function name (a character string)
function to replace x
, defaulting to "replacement." %&% x
where to find the replacement function, defaulting to usual search path
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.
should the replacement use its own environment, or (by default) the one that was originally there?
# NOT RUN {
hack( dir, all.files=getOption( "ls.all.files", TRUE)) # from my '.First'
assign.to.base( "dir", hack( dir, all.files=TRUE))
# }
Run the code above in your browser using DataLab