[prev in list] [next in list] [prev in thread] [next in thread]
List: r-devel
Subject: [Rd] Time to add is.formula() to 'stats'?
From: Mikael Jagan <jaganmn2 () gmail ! com>
Date: 2023-04-08 0:26:16
Message-ID: a4921d32-fee5-d29b-876f-49fbebd7bf86 () gmail ! com
[Download RAW message or body]
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"
["as.is.R" (text/plain)]
## 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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic