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!
> sessionInfo()
R version 2.9.2 (2009-08-24)
i386-pc-mingw32
locale:
LC_COLLATE=Chinese_People's Republic of
China.936;LC_CTYPE=Chinese_People's Republic of
China.936;LC_MONETARY=Chinese_People's Republic of
China.936;LC_NUMERIC=C;LC_TIME=Chinese_People's Republic of China.936
attached base packages:
[1] datasets utils stats graphics grDevices methods base
Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-6609 Web: http://yihui.name
Department of Statistics, Iowa State University
3211 Snedecor Hall, Ames, IA
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.
Seemingly Similar Threads
- deparse() and the 'else' statement
- How to get commands history as a character vector instead of displaying them?
- A question about encoding
- error due to locales again
- Error .jcall(mxe, "S", "fit", c("autorun", "-e", afn, "-o", dirout, : java.lang.NoSuchMethodError: density.Params.readFromArgs([Ljava/lang/String; )Ljava/lang/String;