[Rd] Keep class attribute when applying c() to hexmodes

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Mon May 27 21:24:18 CEST 2024


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



More information about the R-devel mailing list