[R] Modify base R functions in Rprofile.site

cls59 chuck at sharpsteen.net
Sun Oct 4 18:41:20 CEST 2009




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:
> 
> 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
-- 
View this message in context: http://www.nabble.com/Modify-base-R-functions-in-Rprofile.site-tp25735437p25739660.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list