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

Allan Engelhardt allane at cybaea.com
Wed Mar 16 16:25:55 CET 2011



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



More information about the R-help mailing list