From hpages at fhcrc.org  Wed Feb 27 01:42:13 2013
From: hpages at fhcrc.org (=?ISO-8859-1?Q?Herv=E9_Pag=E8s?=)
Date: Tue, 26 Feb 2013 16:42:13 -0800
Subject: [Rd] double bracket stripping names
In-Reply-To: <512C8EB1.8060401@pburns.seanet.com>
References: <512C8EB1.8060401@pburns.seanet.com>
Message-ID: <512D5665.8010902@fhcrc.org>

Hi Patrick,

On 02/26/2013 02:30 AM, Patrick Burns wrote:
> Is it on purpose that `[[` strips the
> names when used on an atomic vector?
>
>  > c(a=1, b=2)[1]
> a
> 1
>  > c(a=1, b=2)[[1]]
> [1] 1

FWIW, here are a couple of other interesting facts about this:

  (a) [[ is about twice faster than [ for me (64-bit Ubuntu)
      on a named atomic vector.

  (b) [[ raises an error if the subscript is out of bounds:

        > c(a=1, b=2)[3]
        <NA>
          NA

        > c(a=1, b=2)[[3]]
        Error in c(a = 1, b = 2)[[3]] : subscript out of bounds

      Can be useful in some contexts.

Cheers,
H.

>
>
>  > sessionInfo()
> R Under development (unstable) (2013-02-11 r61902)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252
> [2] LC_CTYPE=English_United Kingdom.1252
> [3] LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United Kingdom.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
>

-- 
Herv? Pag?s

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



[Rd] double bracket stripping names
=?ISO-8859-1?Q?Herv=E9_Pag=E8s?=