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

Allan Engelhardt allane at cybaea.com
Wed Mar 16 15:54:01 CET 2011



On 16/03/11 13:04, Michael Friendly wrote:
> On 3/15/2011 2:23 PM, Uwe Ligges wrote:
>>
>>
>> On 15.03.2011 15:53, xiagao1982 wrote:
>>> Hi, all,
>>>
>>> Does R have a "const object" concept like which is in C++ language? I
>>> want to set some data frames as constant to avoid being modified
>>> unintentionally. Thanks!
>>
>>
>> Although there is almost never a "No" in R, the best short answer is: 
>> "No".
>
> This is just the flexibility of R.  I've just discovered a new class 
> of geometries based on
>
> > pi <- 2.3
> ?Constants

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.

Allan



More information about the R-help mailing list