g.russell at eos-solutions.com
2010-Feb-09 09:50 UTC
[Rd] Confusing error message for [[.factor (PR#14209)
Full_Name: George Russell Version: 2.10.0 and 2.11.0 Under development (unstable) (2010-02-08 r51108) OS: Windows Submission from: (NULL) (217.111.3.131)> c("a","b")[[c(TRUE,FALSE)]]Error in `[[.default`(factor(c("a", "b")), c(TRUE, FALSE)) : recursive indexing failed at level 1 I find this error message confusing, though after reading the HELP carefully I think I know what is going on. Would not something like "[[ does not work with logical index vectors" be more appropriate? sessionInfo is (for 2.11) : R version 2.11.0 Under development (unstable) (2010-02-08 r51108) i386-pc-mingw32 locale: [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 [4] LC_NUMERIC=C LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics grDevices datasets utils methods base
On 09.02.2010 10:50, g.russell at eos-solutions.com wrote:> Full_Name: George Russell > Version: 2.10.0 and 2.11.0 Under development (unstable) (2010-02-08 r51108) > OS: Windows > Submission from: (NULL) (217.111.3.131) > > >> c("a","b")[[c(TRUE,FALSE)]] > Error in `[[.default`(factor(c("a", "b")), c(TRUE, FALSE)) : > recursive indexing failed at level 1 > > I find this error message confusing, though after reading the HELP carefully I > think I know what is going on. Would not something like "[[ does not work with > logical index vectors" be more appropriate?Well, it is nonsense to use it, but works since TRUE is coerced to 1 as in: list(list(11, 12), 13)[[c(TRUE, TRUE)]] In your example will also fail with integers without a chance to do the recursion. Uwe Ligges> sessionInfo is (for 2.11) : > R version 2.11.0 Under development (unstable) (2010-02-08 r51108) > i386-pc-mingw32 > > locale: > [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 > LC_MONETARY=German_Germany.1252 > [4] LC_NUMERIC=C LC_TIME=German_Germany.1252 > > attached base packages: > [1] stats graphics grDevices datasets utils methods base > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
g.russell at eos-solutions.com wrote:> Full_Name: George Russell > Version: 2.10.0 and 2.11.0 Under development (unstable) (2010-02-08 r51108) > OS: Windows > Submission from: (NULL) (217.111.3.131) > > >> c("a","b")[[c(TRUE,FALSE)]] > Error in `[[.default`(factor(c("a", "b")), c(TRUE, FALSE)) : > recursive indexing failed at level 1 > > I find this error message confusing, though after reading the HELP carefully I > think I know what is going on. Would not something like "[[ does not work with > logical index vectors" be more appropriate?It didn't take particularly careful reading to find this: "The most important distinction between [, [[ and $ is that the [ can select more than one element whereas the other two select a single element." Try this: c("a","b")[[c(1,2)]] c("a","b")[[TRUE]] -Peter Ehlers> > sessionInfo is (for 2.11) : > R version 2.11.0 Under development (unstable) (2010-02-08 r51108) > i386-pc-mingw32 > > locale: > [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 > LC_MONETARY=German_Germany.1252 > [4] LC_NUMERIC=C LC_TIME=German_Germany.1252 > > attached base packages: > [1] stats graphics grDevices datasets utils methods base > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > >-- Peter Ehlers University of Calgary
Duncan Murdoch
2010-Feb-09 17:19 UTC
[Rd] Confusing error message for [[.factor (PR#14209)
On 09/02/2010 4:50 AM, g.russell at eos-solutions.com wrote:> Full_Name: George Russell > Version: 2.10.0 and 2.11.0 Under development (unstable) (2010-02-08 r51108) > OS: Windows > Submission from: (NULL) (217.111.3.131) > > > > c("a","b")[[c(TRUE,FALSE)]] > Error in `[[.default`(factor(c("a", "b")), c(TRUE, FALSE)) : > recursive indexing failed at level 1 >I don't see that. I get this: > c("a","b")[[c(TRUE,FALSE)]] Error in c("a", "b")[[c(TRUE, FALSE)]] : recursive indexing failed at level 1 which differs because c("a", "b") is not a factor.> I find this error message confusing, though after reading the HELP carefully I > think I know what is going on. Would not something like "[[ does not work with > logical index vectors" be more appropriate? >No, because it sometimes does work with logical index vectors: > x <- 1:2 > x[[TRUE]] [1] 1 (Here the TRUE is treated as 1. I think it only works when the logical vector contains TRUE values, FALSE will fail, just as x[[0]] fails.) The problem is that you were asking for the FALSE entry of the TRUE entry of the object, and since you had a simple vector, recursive indexing fails, and that's what the message says. I imagine you had meant to type c("a", "b")[c(TRUE, FALSE)], but how can R know you meant that? Duncan Murdoch