[R] A potential bug for paste() ?

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu May 7 17:55:58 CEST 2009


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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%




More information about the R-help mailing list