Skip to content

Commit

Permalink
Make .make_numeric_version() warn about non-character inputs.
Browse files Browse the repository at this point in the history
Consequence of PR#18548.

git-svn-id: https://svn.r-project.org/R/trunk@84610 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
hornik committed Jun 28, 2023
1 parent 7dfb5b1 commit 1338a95
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/library/base/R/version.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ function(x, strict = TRUE, regexp, classes = NULL)
## Internal creator for numeric version objects.

nms <- names(x)
if(!is.character(x)) {
msg <- gettextf("invalid non-character version specification 'x' (type: %s)",
typeof(x))
if(nzchar(Sys.getenv("_R_CALLS_INVALID_NUMERIC_VERSION_"))) {
calls <- sys.calls()
msg <- paste0(msg, "\n",
gettext("Calls"), ":\n",
paste0(sprintf("%2i: ", seq_along(calls)),
vapply(calls, deparse1, "",
collapse = "\n "),
collapse = "\n"))
}
warning(msg, domain = NA, immediate. = TRUE)
}
x <- as.character(x)
y <- rep.int(list(integer()), length(x))
valid_numeric_version_regexp <- sprintf("^%s$", regexp)
Expand All @@ -61,9 +75,13 @@ function(x, strict = TRUE, regexp, classes = NULL)
## Basic numeric versions.

numeric_version <-
function(x, strict = TRUE)
function(x, strict = TRUE) {
## Be nice.
if(is.numeric_version(x))
return(x)
.make_numeric_version(x, strict,
.standard_regexps()$valid_numeric_version)
}

is.numeric_version <-
function(x)
Expand Down Expand Up @@ -97,6 +115,9 @@ function(x)
package_version <-
function(x, strict = TRUE)
{
## Be nice.
if(is.package_version(x))
return(x)
## Special-case R version lists.
## Currently, do this here for backward compatibility.
## Should this be changed eventually?
Expand Down
Loading

0 comments on commit 1338a95

Please sign in to comment.