Skip to content

Commit 99e696d

Browse files
author
ripley
committed
more details on compareVersion
git-svn-id: https://svn.r-project.org/R/trunk@87243 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 2364527 commit 99e696d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/library/base/man/ns-reflect.Rd

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% File src/library/base/man/ns-reflect.Rd
22
% Part of the R package, https://www.R-project.org
3-
% Copyright 2003-2020 R Core Team
3+
% Copyright 2003-2024 R Core Team
44
% Distributed under GPL 2 or later
55

66
\name{ns-reflect}
@@ -48,10 +48,16 @@ getNamespaceVersion(ns)
4848
and subject to change.
4949

5050
\code{getNamespaceName} and \code{getNamespaceVersion} return the name
51-
and version of the namespace \code{ns}.
51+
and version of the namespace \code{ns} as character strings.
5252

5353
\code{getNamespaceUsers} returns a character vector of the names of
5454
the namespaces that import namespace \code{ns}.
5555
}
56+
\note{
57+
Comparison of versions should use \code{\ink{compareVersion} or
58+
\preformatted{
59+
as.package_version(getNamespaceVersion(ns))
60+
}
61+
}
5662
\keyword{internal}
5763
\author{Luke Tierney}

src/library/utils/R/packages.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ download.packages <- function(pkgs, destdir, available = NULL,
753753
bulkdown <- matrix(character(), 0L, 3L)
754754
else
755755
bulkdown <- NULL
756-
756+
757757
retval <- matrix(character(), 0L, 2L)
758758
for(p in unique(pkgs))
759759
{
@@ -825,7 +825,7 @@ download.packages <- function(pkgs, destdir, available = NULL,
825825
urls <- bulkdown[,3]
826826
destfiles <- bulkdown[,2]
827827
ps <- bulkdown[,1]
828-
828+
829829
res <- try(download.file(urls, destfiles, "libcurl", mode = "wb", ...))
830830
if(!inherits(res, "try-error") && res == 0L) {
831831
if (length(urls) > 1) {
@@ -842,7 +842,7 @@ download.packages <- function(pkgs, destdir, available = NULL,
842842
} else
843843
for(p in ps)
844844
warning(gettextf("download of package %s failed", sQuote(p)),
845-
domain = NA, immediate. = TRUE)
845+
domain = NA, immediate. = TRUE)
846846
}
847847

848848
retval
@@ -1043,8 +1043,11 @@ compareVersion <- function(a, b)
10431043
{
10441044
if(is.na(a)) return(-1L)
10451045
if(is.na(b)) return(1L)
1046+
## The nest two could be skipped if(inherits(x), "numeric_version")
1047+
## but the saving would be small.
10461048
a <- as.integer(strsplit(a, "[.-]")[[1L]])
10471049
b <- as.integer(strsplit(b, "[.-]")[[1L]])
1050+
## This does not handle malformed inputs which will give an error.
10481051
for(k in seq_along(a))
10491052
if(k <= length(b)) {
10501053
if(a[k] > b[k]) return(1) else if(a[k] < b[k]) return(-1L)

src/library/utils/man/compareVersion.Rd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% File src/library/utils/man/compareVersion.Rd
22
% Part of the R package, https://www.R-project.org
3-
% Copyright 1995-2007 R Core Team
3+
% Copyright 1995-2024 R Core Team
44
% Distributed under GPL 2 or later
55

66
\name{compareVersion}
@@ -19,6 +19,8 @@ compareVersion(a, b)
1919
\code{0} if the numbers are equal, \code{-1} if \code{b} is later
2020
and \code{1} if \code{a} is later (analogous to the C function
2121
\code{strcmp}).
22+
23+
Gives an \R error on malformed inputs.
2224
}
2325
\details{
2426
\R package version numbers are of the form \code{x.y-z} for integers

0 commit comments

Comments
 (0)