New to R, I had the bad idea to send a bug report about '[' not knowing it had a drop= argument. Now, I wonder about the absence of this argument in subset... In both availabe methods (see below), there is a ... argument, but this argument is not used in either. Rather, subset.data.frame explitictly passes drop=F in 1 instance. Before I start patching (for my own use): what is the reason for this?>subset.defaultfunction (x, subset, ...) x[subset & !is.na(subset)]>subset.data.framefunction (x, subset, select, ...) { if (missing(subset)) r <- TRUE else { e <- substitute(subset) r <- eval(e, x, parent.frame()) r <- r & !is.na(r) } if (missing(select)) vars <- TRUE else { nl <- as.list(1:ncol(x)) names(nl) <- names(x) vars <- eval(substitute(select), nl, parent.frame()) } x[r, vars, drop = FALSE] } RenE J.V. Bertin College de France/LPPA 11, place Marcelin Berthelot 75005 Paris, France _________________________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"RenE J.V. Bertin" <rjvbertin at hotmail.com> writes:> New to R, I had the bad idea to send a bug report about '[' not > knowing it had a drop= argument. Now, I wonder about the absence of > this argument in subset... > > In both availabe methods (see below), there is a ... argument, but > this argument is not used in either. Rather, subset.data.frame > explitictly passes drop=F in 1 instance. > Before I start patching (for my own use): what is the reason for this?"..." is generally used in methods, in case someone defines a method with further arguments for a subclass and wants to use NextMethod(). It's not a bug that no existing method actually uses it. There's no particular reason not to pass ... on to the indexing in subset.default, except that the author didn't think about it. I don't think the default method gets used much, but it might be useful to change it to function (x, subset, ...) x[subset & !is.na(subset),...] (This would likely change the semantics for the case where x is a matrix or array. Possibly for the better.) In subset.data.frame, the drop=F ensures that you get a data frame as the result even if only a single column is selected (or there was only a single column to begin with). I think this is as it should be. If you look closer, you'll see that the drop=F is actually applied in *all* instances and that all four arguments to [.data.frame are passed explicitly so there's no point in passing ... there. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._