Hello all, I'm having a problem when overwriting the '<-' function and was told I'd better post it here for help. The reason why I need to overwrite it is complicated and not easy to tell in a few words; but this seems the only clean option other than hacking R's core source code. My code looks like: # in .onLoad of a package; or if you want to test, put it in a function env <- as.environment('package:base') unlockBinding('<-',env) assign('<-', newAssign, envir=env) .Internal(lockBinding(as.name('<-'), env)) #not using lockBinding directly because it calls '<-' It gave me this error: Error: evaluation nested too deeply: infinite recursion / options(expressions=)? Any suggestion is appreciated! -- Yi
luke at stat.uiowa.edu
2009-Jan-23 21:25 UTC
[Rd] overwriting '<-' and infinite recursions
While it _may_ be possible to make this work in current R (I don't know if it is) this is a Really Bad Idea as it will affect every other piece of R code run on the system. It also may not work at all in future versions of R (assignment is sufficiently core functionality that it may not be implemented via a function at all in some circumstances). Locked bindings are locked for a reason: we as developers can assume that their values are what we intend them to be. If those values are changed then that assumption fails and some things may stop working. If you explain what your needs are someone on the list can probably help you find a more effective and less intrusive way of doing it. luke On Fri, 23 Jan 2009, Yi Zhang wrote:> Hello all, > > I'm having a problem when overwriting the '<-' function and was told > I'd better post it here for help. The reason why I need to overwrite > it is complicated and not easy to tell in a few words; but this seems > the only clean option other than hacking R's core source code. My code > looks like: > > # in .onLoad of a package; or if you want to test, put it in a function > env <- as.environment('package:base') > unlockBinding('<-',env) > assign('<-', newAssign, envir=env) > .Internal(lockBinding(as.name('<-'), env)) > #not using lockBinding directly because it calls '<-' > > It gave me this error: Error: evaluation nested too deeply: infinite > recursion / options(expressions=)? > > Any suggestion is appreciated! > > -- > Yi > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics and Fax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke at stat.uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
Seemingly Similar Threads
- Bug report: R.home() cause package Rcpp failed executing sourceCpp, similar bug are labeled "BUG 16660" since 2016 and here I could provide a solution that tested in my laptop.
- Problem with "setMethod" in R package
- Overwriting imported function in another package
- [External] Re: Building Packages. (fwd)
- Sealed for setGeneric