[R] A potential bug for paste() ?

Phil Spector spector at stat.berkeley.edu
Thu May 7 18:20:45 CEST 2009


Theoph is in the datasets package, so it should be 
available in all versions of R:

> class(Theoph)
[1] "nfnGroupedData" "nfGroupedData"  "groupedData"    "data.frame"

The key to what's happening is that there are some methods
for groupedData objects in the nlme library, which I suspect
the original poster had loaded in Windows, but not Unix.

Here's what I see on a Linux system:

> all(paste(Theoph[1],Theoph[2])==paste(Theoph[[1]],Theoph[[2]]))
[1] FALSE
> library(nlme)
> all(paste(Theoph[1],Theoph[2])==paste(Theoph[[1]],Theoph[[2]]))
[1] TRUE

So if nlme is loaded, the following methods are available for 
groupedData objects:

> methods(class='groupedData')
  [1] as.data.frame.groupedData* asTable.groupedData*
  [3] collapse.groupedData*      formula.groupedData*
  [5] [.groupedData*             isBalanced.groupedData*
  [7] lme.groupedData*           lmList.groupedData*
  [9] print.groupedData*         update.groupedData*

Thus subscripting for these objects is performed differently when
the nlme package is loaded.
                                        - Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Thu, 7 May 2009, Gavin Simpson wrote:

> On Thu, 2009-05-07 at 09:38 -0500, Jun Shen wrote:
>> Hi, everyone,
>>
>> Try the following command to see if you get TRUE or FALSE. I get FALSE on a
>> unix platform but TRUE on Windows. Any comment?
>>
>> all(paste(Theoph[1],Theoph[2])==paste(Theoph[[1]],Theoph[[2]]))
>
> And what is Theoph? Please do read the posting guide and provide a
> reproducible example.
>
> Is Theoph a list?
>
>> a <- list(A = rnorm(10), B = rnorm(10))
>> paste(a[1], a[2])
> [1] "c(0.511810414967963, 0.165995305876871, 1.22637694512945,
> -0.496453787173788, 0.325876407556065, 1.97392856823209,
> -0.228962880984580, -0.172306887133861, -0.881280038259407,
> -0.216958955239245) c(-0.281058662811336, 0.918418337792562,
> -1.44005513590710, 0.22857441100305, 0.840138552938062,
> 0.0555436312146647, -0.602645008995437, -0.158866265592772,
> 0.959478898002479, -0.892389972305427)"
>> paste(a[[1]], a[[2]])
> [1] "0.511810414967963 -0.281058662811336"
> [2] "0.165995305876871 0.918418337792562"
> [3] "1.22637694512945 -1.44005513590710"
> [4] "-0.496453787173788 0.22857441100305"
> [5] "0.325876407556065 0.840138552938062"
> [6] "1.97392856823209 0.0555436312146647"
> [7] "-0.228962880984580 -0.602645008995437"
> [8] "-0.172306887133861 -0.158866265592772"
> [9] "-0.881280038259407 0.959478898002479"
> [10] "-0.216958955239245 -0.892389972305427"
>> typeof(a[[1]])
> [1] "double"
>> typeof(a[1])
> [1] "list"
>
> If it is, note that [ and [[ do not return the same thing for a list and
> as such it is not surprising that they are not equal, pasted or
> otherwise.
>
> G
> --
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
> ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
> Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
> Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
> UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list