Schuhmacher, Dominic
2024-May-27 15:49 UTC
[Rd] Keep class attribute when applying c() to hexmodes
Dear list,
The following behavior in base R is unexpected to me:
a <- as.hexmode("99ac")
b <- as.hexmode("9ce5")
v <- c(a,b)
v
#> [1] 39340 40165
class(v)
#> [1] "integer"
Is there a good reason why v should not be of class "hexmode"?
I can see that this is exactly as documented. The help for `c()` only says that
the arguments are coerced to a common type (which is integer anyway) and that
all attributes except names are removed. On the other hand, it says further down
that "c methods other than the default are not required to remove
attributes (and they will almost certainly preserve a class attribute)".
So couldn't (or even shouldn't) there be a c.hexmode that keeps the
class attribute?
Best regards,
Dominic
------------------------------------------
Prof. Dr. Dominic Schuhmacher
Institute for Mathematical Stochastics
University of G?ttingen, Germany
https://dschuhm1.pages.gwdg.de
Duncan Murdoch
2024-May-27 19:24 UTC
[Rd] Keep class attribute when applying c() to hexmodes
On 2024-05-27 11:49 a.m., Schuhmacher, Dominic wrote:> Dear list, > > The following behavior in base R is unexpected to me: > > a <- as.hexmode("99ac") > b <- as.hexmode("9ce5") > v <- c(a,b) > v > #> [1] 39340 40165 > class(v) > #> [1] "integer" > > Is there a good reason why v should not be of class "hexmode"? > > I can see that this is exactly as documented. The help for `c()` only says that the arguments are coerced to a common type (which is integer anyway) and that all attributes except names are removed. On the other hand, it says further down that "c methods other than the default are not required to remove attributes (and they will almost certainly preserve a class attribute)". > > So couldn't (or even shouldn't) there be a c.hexmode that keeps the class attribute?I believe there could. If you think there should, then you should submit a patch containing it to bugs.r-project.org. Based on c.Date, here's a first attempt: c.hexmode <- function(...) as.hexmode(c(unlist(lapply(list(...), function(e) unclass(as.hexmode(e)))))) If you want this to be incorporated into R, you should test it, document it, and submit a patch containing it. Duncan Murdoch