Skip to content
Prev 25802 / 398502 Next

problem with attr()

I got this wired behaviour of the attr() function using R-1.6.1 on both 
linux redhat 7.3 (i386) and Solaris 8 (Sparc):

 > tmp <- list(id=1)
 >
 > attr(tmp,"n.ch") <- 2
 > attr(tmp,"n") <- 1
 > tmp
$id
[1] 1

attr(,"n.ch")
[1] 2
attr(,"n")
[1] 1
 >
 > attributes(tmp)
$names
[1] "id"

$n.ch
[1] 2

$n
[1] 1

 > attr(tmp,"names")
[1] "id"
 > attr(tmp,"n.ch")
[1] 2
 > attr(tmp,"n")
NULL
 >

The attr()function doesn't find the 'n' attribute, however, if I don't 
create the 'n.ch' attribute, it finds it!  That is:

 > tmp <- list(id=1)
 > attr(tmp,'n')
NULL
 > attr(tmp,'n') <- 1
 > attr(tmp,'n')
[1] 1
 >