On 04/10/2009 12:41 PM, cls59 wrote:


Yihui Xie wrote:
Hi everyone,

I want to modify two base R functions 'parse' and 'deparse'
immediately after R has started, so I added some code in the file
'Rprofile.site' under the 'etc' directory. Here is a simple example:

Why not just modify their source, and rebuild R?

Duncan Murdoch


parse=function(...){
    base::parse(...)
}

I'll get an error when I start R as follows:

Error: cannot change value of locked binding for 'parse'

Is there a solution for my problem? Please note that I *have to*
override the function names. Thanks very much!




Hi Yihui,

I have had cause to do some some similar things to Sweave functions-- maybe
the following will help:

  # Find out where the function lives.
  env <- as.environment( 'package:base' )

  # Crack the binding.
  unlockBinding( 'parse', env )

  # Replace the function.
  assignInNamespace( 'parse', function(...){
# Your function here, or an object that contains it.

   }, ns = 'base' )

  # Relock the binding.
  lockBinding( 'parse', env )


Note that the above is *very* dark voodoo-- it may cause unforeseen
consequences.

Good luck!

-Charlie

-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to