I know that it has been discussed in the past, but I wanted to ask to revisit the idea of exporting
is.formula <- function(x) inherits(x, "formula") from 'stats', parallel to is.data.frame() in 'base', given how widely formulae are used these days in conjunction with data frames, even outside of model fitting functions (e.g., for split-apply). One could argue that today data frames and formulae go hand in hand, and that the lack of is.formula() is a rather ugly asymmetry ... Furthermore, 'formula' is one of the only S3 classes generated by way of a primitive (the `~` operator, calling do_tilde() in names.c), so it is really in some sense "special" { compared to 'factor', 'POSIXlt', etc. }. What do people think? In case it helps, I've gathered some data from 'base' and the so-called 'defaultPackages', reproduced by the attached R script ... see below. Mikael ---------------------------- 1. For which X does is.X() have no corresponding as.X()? [1] "R" "atomic" "element" "finite" "hashtab" "infinite" [7] "language" "leaf" "loaded" "mts" "na" "nan" [13] "object" "primitive" "recursive" "tskernel" "unsorted" 2. For which Y does as.Y() have no corresponding is.Y()? [1] "Date" "POSIXct" "POSIXlt" "dendrogram" [5] "difftime" "dist" "formula" "graphicsAnnot" [9] "hclust" "hexmode" "octmode" "person" [13] "personList" "roman" 3. For which Z does is.Z() just call inherits(., "Z")? [1] "data.frame" "factor" "numeric_version" "ordered" [5] "package_version" "raster" "relistable" "table"
## all as.*() and is.*() in 'base' and 'defaultPackages' pkg <- c("base", "datasets", "grDevices", "graphics", "methods", "stats", "utils") getExports <- function(s) names(as.environment(paste0("package:", s))) nms <- sort(unlist(lapply(pkg, getExports))) as. <- nms[startsWith(nms, "as.")] is. <- nms[startsWith(nms, "is.")] ## excluding methods and assignments as.. <- c("as.data.frame", grep("([.].+[.]|<-)", as., value=TRUE, invert=TRUE)) is.. <- c("is.data.frame", grep("([.].+[.]|<-)", is., value=TRUE, invert=TRUE)) cl.as <- sub("^as[.]", "", as..) cl.is <- sub("^is[.]", "", is..) callsInherits <- function(x) is.call(b <- body(match.fun(x))) && b[[1L]] == "inherits" ## missing as.*() setdiff(cl.is, cl.as) ## missing is.*() setdiff(cl.as, cl.is) ## is.*() just calling inherits() cl.is[vapply(is.., callsInherits, NA)]
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel