Apparently the patch file got eaten. Let me try again with a .txt extension.
-Ken
> -----Original Message-----
> From: Ken Williams
> Sent: Wednesday, April 11, 2012 10:28 AM
> To: [email protected]
> Subject: [patch] giving library() a 'version' argument
>
> I've made a small enhancement to R that would help developers better
> control what versions of code we're using where.
> [...]
CONFIDENTIALITY NOTICE: This e-mail message is for the sole use of the intended
recipient(s) and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution of any kind is strictly
prohibited. If you are not the intended recipient, please contact the sender
via reply e-mail and destroy all copies of the original message. Thank you.
Index: src/library/base/man/library.Rd
===================================================================
--- src/library/base/man/library.Rd (revision 58980)
+++ src/library/base/man/library.Rd (working copy)
@@ -21,7 +21,7 @@
character.only = FALSE, logical.return = FALSE,
warn.conflicts = TRUE, quietly = FALSE,
keep.source = getOption("keep.source.pkgs"),
- verbose = getOption("verbose"))
+ verbose = getOption("verbose"), version)
require(package, lib.loc = NULL, quietly = FALSE,
warn.conflicts = TRUE,
@@ -59,6 +59,9 @@
\item{quietly}{a logical. If \code{TRUE}, no message confirming
package loading is printed, and most often, no errors/warnings are
printed if package loading fails.}
+ \item{version}{the minimum acceptable version of the package to load.
+ If a lesser version is found, the package will not be loaded and an
+ exception will be thrown.}
}
\details{
\code{library(package)} and \code{require(package)} both load the
@@ -189,6 +192,10 @@
search() # "splines", too
detach("package:splines")
+# To require a specific minimum version:
+library(splines, '2.14')
+detach("package:splines")
+
# if the package name is in a character vector, use
pkg <- "splines"
library(pkg, character.only = TRUE)
Index: src/library/base/R/library.R
===================================================================
--- src/library/base/R/library.R (revision 58980)
+++ src/library/base/R/library.R (working copy)
@@ -32,7 +32,7 @@
function(package, help, pos = 2, lib.loc = NULL, character.only = FALSE,
logical.return = FALSE, warn.conflicts = TRUE,
quietly = FALSE, keep.source = getOption("keep.source.pkgs"),
- verbose = getOption("verbose"))
+ verbose = getOption("verbose"), version)
{
if (!missing(keep.source))
warning("'keep.source' is deprecated and will be ignored")
@@ -276,6 +276,11 @@
stop(gettextf("%s is not a valid installed package",
sQuote(package)), domain = NA)
pkgInfo <- readRDS(pfile)
+ if (!missing(version)) {
+ pver <- pkgInfo$DESCRIPTION["Version"]
+ if (compareVersion(pver, as.character(version)) < 0)
+ stop("Version ", version, " of '", package, "' required,
but only ", pver, " is available")
+ }
testRversion(pkgInfo, package, pkgpath)
## avoid any bootstrapping issues by these exemptions
if(!package %in% c("datasets", "grDevices", "graphics", "methods",
@@ -332,10 +337,18 @@
stop(gettextf("package %s does not have a NAMESPACE and should be
re-installed",
sQuote(package)), domain = NA)
}
- if (verbose && !newpackage)
- warning(gettextf("package %s already present in search()",
- sQuote(package)), domain = NA)
+ if (!newpackage) {
+ if (verbose)
+ warning(gettextf("package %s already present in search()",
+ sQuote(package)), domain = NA)
+ if (!missing(version)) {
+ pver <- packageVersion(package)
+ if (compareVersion(as.character(pver), as.character(version)) <
0)
+ stop("Version ", version, " of '", package,"' required, ",
+ "but a lesser version ", pver, " is already loaded")
+ }
+ }
}
else if(!missing(help)) {
if(!character.only)
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel