Skip to content

Commit b684883

Browse files
author
smeyer
committed
tweak c86424 for empty input
git-svn-id: https://svn.r-project.org/R/trunk@87831 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent f3568d9 commit b684883

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/library/base/R/version.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/base/R/version.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2024 The R Core Team
4+
# Copyright (C) 1995-2025 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -345,6 +345,8 @@ function(..., recursive = FALSE)
345345
duplicated.numeric_version <-
346346
function(x, incomparables = FALSE, ...)
347347
{
348+
n <- length(x)
349+
if (n < 2L) return(logical(n))
348350
x <- unclass(x)
349351
lens <- lengths(x, use.names = FALSE)
350352
need <- max(lens) - lens

tests/reg-tests-1e.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,18 @@ stopifnot(exprs = {
18671867
## all these used to error in reformulate() in R < 4.5.0
18681868

18691869

1870+
## duplicated(<numeric_version>), especially for empty input
1871+
options(warn = 2) # should already be set from the top
1872+
x <- numeric_version("1")
1873+
stopifnot(exprs = {
1874+
identical(duplicated(x[NULL]), logical(0L)) # should not warn
1875+
identical(duplicated(x), FALSE)
1876+
identical(duplicated(c(x,x)), c(FALSE, TRUE))
1877+
})
1878+
## only in R-devel with PR#18699, the first produced a warning
1879+
## In max(lens) : no non-missing arguments to max; returning -Inf
1880+
1881+
18701882

18711883
## keep at end
18721884
rbind(last = proc.time() - .pt,

0 commit comments

Comments
 (0)