Skip to content

Odd outcome of attr with environments (PR#2148)

2 messages · j.c.rougier@durham.ac.uk, Thomas Lumley

#
Hi everyone,

I think the following error is slightly odd:
<environment: 0x8a425b8>
Error: invalid (NULL) left side of assignment

But naturally this works
<environment: 0x8a425b8>
attr(,"foo")
 [1]  1  2  3  4  5  6  7  8  9 10

I would have thought that "fred" and "happy()" were synonymous, so I
was surprised that I could not attach an attribute to the environment
using "happy()".  Of course in practice I can get round this by doing
<environment: 0x8a425b8>
attr(,"foo")
[1] 5 4 3 2 1
<environment: 0x8a425b8>
attr(,"foo")
[1] 5 4 3 2 1

but I wondered what was going on.

Cheers, Jonathan.

--please do not edit the information below--

Version:
 platform = i686-pc-linux-gnu
 arch = i686
 os = linux-gnu
 system = i686, linux-gnu
 status = 
 major = 1
 minor = 6.0
 year = 2002
 month = 10
 day = 01
 language = R

Search Path:
 .GlobalEnv, Autoloads, package:base

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Fri, 11 Oct 2002 j.c.rougier@durham.ac.uk wrote:

            
It's nothing to do with environments.  happy() is not an variable, so you
can't modify it: eg

R> f<-function(){ 42}
R> f()<-1
Error: invalid (NULL) left side of assignment
R> attr(f(),"foo")<-1
Error: invalid (NULL) left side of assignment
R> f()[1]<-1
Error: invalid (NULL) left side of assignment


	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._