MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #16705] inconsistent error reporting in reshape() #6089

Open MichaelChirico opened 4 years ago

MichaelChirico commented 4 years ago

If you supply one nonexistent name for the 'v.names' argument to reshape you get a result (probably not the one you want, but equivalent to v.names=character()). If you supply more than one nonexistant name it throws an error. Should it throw an error in either case? Or should it ignore v.names entries not in the data.frame 'data' in both cases?

DF <- data.frame(Time=rep(1:4,3), A=rep(11:13,each=4),B=rep(21:23,each=4),C=rep(21:23,each=4),D=rep(31:33,each=4)) reshape(DF, timevar="Time", idvar="A", direction="wide", v.names=c("noSuchName")) # A B C D

1 11 21 21 31

5 12 22 22 32

9 13 23 23 33

reshape(DF, timevar="Time", idvar="A", direction="wide", v.names=c("noSuchName","anotherBadName"))

Error in [.data.frame(thistime, match(rval[, idvar], thistime[, idvar]), :

# undefined columns selected

sessionInfo()

R Under development (unstable) (2016-02-02 r70074) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 14.04.3 LTS

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base


METADATA

MichaelChirico commented 4 years ago

Created attachment 2580 [details] patch for stats::reshape

It's a consequence of the way [.data.frame automatically determines the 'drop' argument. Compare:

iris[, "noSuchName"]

Error in [.data.frame(iris, , "noSuchName") : undefined columns selected

iris[1:3, "noSuchName"]

NULL

iris[1:3, c("noSuchName", "anotherBadName")]

Error in [.data.frame(iris, 1:3, c("noSuchName", "anotherBadName")) : undefined columns selected

iris[1:3, "noSuchName", drop = FALSE]

Error in [.data.frame(iris, 1:3, "noSuchName", drop = FALSE) : undefined columns selected

As for reshape, I lean toward making this an error regardless of the length of v.names. See the attached patch.


METADATA

INCLUDED PATCH