Skip to content

Subscripting fails if name of element is "" (PR#8161)

2 messages · Jens Oehlschlägel, Thomas Lumley

#
Dear all,

I resend this mail because it was blocked: I submitted a bug from the r-bug
webpage and hypatia seems to block mail that is send from a different IP
than that usually associated with the email. Looks like it is currently
impossible to correctly submit bugs from the website. However, here is the
original bug report:

(PR#8161)

Dear all,

The following shows cases where accessing elements via their name fails (if
the
name is a string of length zero). 

Best regards


Jens Oehlschl?gel
a      <NA> 
   1    2    3
+ print(p[[i]])
[1] 1
[1] 2
[1] 3
+ print(p[i])
a 
1 
<NA> 
  NA 
<NA> 
   3
+ print(p[[i]])
[1] 1
[1] 2
[1] 3
+ print(p[i])
$a
[1] 1

$"NA"
NULL

$"NA"
[1] 3
_              
platform i386-pc-mingw32
arch     i386           
os       mingw32        
system   i386, mingw32  
status                  
major    2              
minor    1.1            
year     2005           
month    06             
day      20             
language R




# -- replication code ----------------------------------

p <- 1:3
names(p) <- c("a","", as.character(NA))
p

for (i in names(p))
		 print(p[[i]])
		 
# error 1: vector subsripting with "" fails in second element
for (i in names(p))
		 print(p[i])

# error 2: print method for list shows no name for second element
p <- as.list(p)


for (i in names(p))
		 print(p[[i]])
		 
# error 3: list subsripting with "" fails in second element
for (i in names(p))
		 print(p[i])




--
#
On Fri, 30 Sep 2005, "Jens Oehlschl?gel" wrote:
This looks deliberate (there is a function NonNullStringMatch that does 
the matching).  I assume this is because there is no other way to 
indicate that an element has no name.

If so, it is a documentation bug -- help(names) and FAQ 7.14 should 
specify this behaviour.  Too late for 2.2.0, unfortunately.

 	-thomas
Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle