Moved to Bugzilla as a wishlist item:
https://bugs.r-project.org/show_bug.cgi?id=18983
Mikael
Date: Mon, 22 Dec 2025 21:16:11 +0100
From: Kurt Hornik <[email protected]>
>>>>> Ben Bolker writes:
Right, but as Gabor already pointed out, now that we have xtfrm (which
has a numeric_version method) there is no reason why which.max() and
which.min() should not take advantage of it in the case of classed
arguments.
I'll try to discuss this within R Core: patches welcome :-)
Best
-k
> Sorry if this is obvious, but `which.max()` is hard-coded in C, with a
> step at the beginning that attempts to coerce the vector to numeric
>
https://github.com/r-devel/r-svn/blob/5e0a5f013292e56c73360addb61ddaa7d3ca16a2/src/main/summary.c#L1027
> Another alternative (your methods are probably better?)
> which.max.nv <- function(x) (seq_along(x)[x == max(x)])[1]
> It seems like too much work to change the definition of package versions
> (which is a list of integer vectors, under the hood) or to make a generic
> S3 method for which.max, given that the workarounds are so easy.
> Also, the documentation explicitly calls out this limitation:
> x: numeric (logical, integer or double) vector or an R object
> for which the internal coercion to ‘double’ works whose ‘min’
> or ‘max’ is searched for.
> On Sat, Dec 20, 2025 at 10:35 AM Gabor Grothendieck <[email protected]>
> wrote:
>> versions <- c("9.10", "9.2")
>> nv <- numeric_version(versions)
>> class(nv)
>> ## [1] "numeric_version"
>>
>> max(nv) # ok
>> ## [1] ‘9.10’
>>
>> versions[tail(order(nv), 1)] # ok
>> ## [1] "9.10"
>>
>> sort(nv, decreasing = TRUE)[1] # ok
>> ## [1] ‘9.10’
>>
>> versions[which.max(xtfrm(nv))] # ok
>> ## [1] "9.10"
>>
>> versions[which.max(nv)] # error
>> ## Error in which.max(nv) : 'list' object cannot be coerced to type
>> 'double'
>>
>>
>> --
>> Statistics & Software Consulting
>> GKX Group, GKX Associates Inc.
>> tel: 1-877-GKX-GROUP
>> email: ggrothendieck at gmail.com
>>
>> ______________________________________________
>> [email protected] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
> [[alternative HTML version deleted]]
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel