[R] Does R have a "const object"?

luke-tierney at uiowa.edu luke-tierney at uiowa.edu
Wed Mar 16 16:49:36 CET 2011


Just as a heads-up: it is likely that unlocking the bindings in base
for pi, T, F, probably all BULTIN and SPECIAL functions, and possibly
more, will start signaling warnings in the near future.  Doing this
may be useful at times for debugging but it can mess up assumptions
others make about how things in base work and so reduce code
reliability.

Best,

luke

On Wed, 16 Mar 2011, Allan Engelhardt wrote:

>
>
> On 16/03/11 15:04, Gabor Grothendieck wrote:
>> On Wed, Mar 16, 2011 at 10:54 AM, Allan Engelhardt<allane at cybaea.com> 
>> wrote:
>>> [...]
>>> Yes, but you can still print(base::pi) and rm(pi) to get back to our flat
>>> world, and you can't
>>> 
>>>> assign("pi", 4, pos = "package:base")
>>> Error in assign("pi", 4, pos = "package:base") :
>>>   cannot change value of locked binding for 'pi'
>>> 
>>> Just a feature of the search path.  Morale: if you want base::pi, write
>>> base::pi.
>>> 
>> Try this:
>> 
>>> old.pi<- pi
>>> assignInNamespace("pi", 2.3, ns = "base")
>>> pi
>> [1] 2.3
>>> base::pi
>> [1] 2.3
>
> Ah!  assignInNamespace does an unlockBinding under the covers which obviously 
> is Evil(tm).  The answer clearly is to do
>
> assignInNamespace("unlockBinding", function (...) {warning("be safe");}, 
> ns="base")
>
> in your .Rprofile!  Let's Keep R Safe, Folks!
>
> Allan
>
> ______________________________________________
> R-help at 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.
>

-- 
Luke Tierney
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



More information about the R-help mailing list