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

From: Allan Engelhardt <allane_at_cybaea.com>
Date: Wed, 16 Mar 2011 15:25:55 +0000

On 16/03/11 15:04, Gabor Grothendieck wrote:
> On Wed, Mar 16, 2011 at 10:54 AM, Allan Engelhardt<allane@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. Received on Wed 16 Mar 2011 - 15:29:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Mar 2011 - 16:20:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive