From tlumley at u.washington.edu  Fri Sep 30 17:47:20 2005
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Fri, 30 Sep 2005 08:47:20 -0700 (PDT)
Subject: [Rd] Subscripting fails if name of element is "" (PR#8161)
In-Reply-To: <14134.1128085960@www76.gmx.net>
References: <14134.1128085960@www76.gmx.net>
Message-ID: <Pine.LNX.4.63a.0509300844400.29284@homer23.u.washington.edu>

On Fri, 30 Sep 2005, "Jens Oehlschl?gel" wrote:
> Dear all,
>
> The following shows cases where accessing elements via their name fails (if
> the
> name is a string of length zero).


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




>
> Best regards
>
>
> Jens Oehlschl?gel
>
>
>> p <- 1:3
>> names(p) <- c("a","", as.character(NA))
>> p
>   a      <NA>
>   1    2    3
>>
>> for (i in names(p))
> + print(p[[i]])
> [1] 1
> [1] 2
> [1] 3
>>
>> # error 1: vector subsripting with "" fails in second element
>> for (i in names(p))
> + print(p[i])
> a
> 1
> <NA>
>  NA
> <NA>
>   3
>>
>> # error 2: print method for list shows no name for second element
>> p <- as.list(p)
>>
>>
>> for (i in names(p))
> + print(p[[i]])
> [1] 1
> [1] 2
> [1] 3
>>
>> # error 3: list subsripting with "" fails in second element
>> for (i in names(p))
> + print(p[i])
> $a
> [1] 1
>
> $"NA"
> NULL
>
> $"NA"
> [1] 3
>
>>
>> version
>         _
> 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])
>
>
>
>
> --
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

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


[Rd] Subscripting fails if name of element is "" (PR#8161)
Thomas Lumley