J.C.Rougier@durham.ac.uk
2000-Oct-16 13:01 UTC
[Rd] print problem with data frames (PR#698)
Another one from the student computer practicals: it is possible to create a dataframe that cannot be printed. Thus> fred <- data.frame(happy=c(TRUE, FALSE, TRUE), sad=7:9) > tmp <- fred[c(FALSE, FALSE, TRUE, TRUE)] # no error message! > tmpError in as.matrix.data.frame(x) : dim<- length of dims do not match the length of object> print.default(tmp)$"NA" NULL $"NA" NULL attr(,"class") [1] "data.frame" This obviously relates to my previous posting to r-devel about subscripting objects with logical vectors that are not the right length. Cheers, Jonathan. --please do not edit the information below-- Version: platform = sparc-sun-solaris2.7 arch = sparc os = solaris2.7 system = sparc, solaris2.7 status = major = 1 minor = 1.1 year = 2000 month = August day = 15 language = R Search Path: .GlobalEnv, Autoloads, package:base -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 16 Oct 2000 15:01:28 +0200 (MET DST), you wrote in message <200010161301.PAA02685@pubhealth.ku.dk>:>Another one from the student computer practicals: it is possible >to create a dataframe that cannot be printed. Thus > >> fred <- data.frame(happy=c(TRUE, FALSE, TRUE), sad=7:9) >> tmp <- fred[c(FALSE, FALSE, TRUE, TRUE)] # no error message! >> tmp >Error in as.matrix.data.frame(x) : dim<- length of dims do not match the length of object...>This obviously relates to my previous posting to r-devel about >subscripting objects with logical vectors that are not the right >length.In this case the problem is that the indexing is missing a comma. You should have had tmp <- fred[c(FALSE, FALSE, TRUE, TRUE),] because that's how you select cases. Without the comma, you're treating the data.frame as a list containing two entries ("happy" and "sad"), then creating a new one consisting of the 3rd and 4th entries of that list (which are NA). It still has the data.frame class though, so you get the error when you try to print it. I think it might be nice to warn people about that kind of indexing, because it's rarely intentional, but it would be really hard to do. You'd need something like a "novice warning level" option, and writers of procedures would have to anticipate all the common errors novices would make. Duncan Murdoch P.S. to the developers: When I tried to copy and paste Jonathan's code into a newly opened copy of R using the Edit menu, I got an error I haven't seen before when I tried to open the menu: "No selection". I can't reproduce this reliably yet, but I'll let you know if I figure out what triggered it. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
This is known (at least to some of us) and there are other problems with data frames and their printing. Hopefully I will have some fixes for 1.2. Robert On Mon, Oct 16, 2000 at 03:01:28PM +0200, J.C.Rougier@durham.ac.uk wrote:> Another one from the student computer practicals: it is possible > to create a dataframe that cannot be printed. Thus > > > fred <- data.frame(happy=c(TRUE, FALSE, TRUE), sad=7:9) > > tmp <- fred[c(FALSE, FALSE, TRUE, TRUE)] # no error message! > > tmp > Error in as.matrix.data.frame(x) : dim<- length of dims do not match the length of object > > print.default(tmp) > $"NA" > NULL > > $"NA" > NULL > > attr(,"class") > [1] "data.frame" > > This obviously relates to my previous posting to r-devel about > subscripting objects with logical vectors that are not the right > length. > > Cheers, Jonathan. > > --please do not edit the information below-- > > Version: > platform = sparc-sun-solaris2.7 > arch = sparc > os = solaris2.7 > system = sparc, solaris2.7 > status = > major = 1 > minor = 1.1 > year = 2000 > month = August > day = 15 > language = R > > Search Path: > .GlobalEnv, Autoloads, package:base > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- +-------------------------------------------------------------------------+ | Robert Gentleman phone : (64-9) 3737-599 ext 3946 | | Senior Lecturer fax : (64-9) 3737-018 | | Department of Statistics office : Room 206 Maths/Physics | | University of Auckland email : rgentlem@stat.auckland.ac.nz | +-------------------------------------------------------------------------+ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._