Skip to content

Commit

Permalink
unload namespace before reinstalling, #4403
Browse files Browse the repository at this point in the history
  • Loading branch information
jangorecki committed Apr 27, 2020
1 parent dd7609e commit 8b1aa6a
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions R/devel.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dcf.lib = function(pkg, field, lib.loc=NULL){
if (nzchar(dcf)) read.dcf(dcf, fields=field)[1L] else NA_character_
}

dcf.repo = function(pkg, repo, field, type){
dcf.repo = function(pkg, repo, field, type) {
# get DESCRIPTION metadata field from remote PACKAGES file
stopifnot(is.character(pkg), is.character(field), length(pkg)==1L, length(field)==1L, is.character(repo), length(repo)==1L, field!="Package")
idx = file(file.path(contrib.url(repo, type=type),"PACKAGES"))
Expand All @@ -17,22 +17,33 @@ dcf.repo = function(pkg, repo, field, type){
dcf[dcf[,"Package"]==pkg, field][[1L]]
}

update.dev.pkg = function(object="data.table", repo="https://Rdatatable.gitlab.io/data.table", field="Revision", type=getOption("pkgType"), lib=NULL, ...){
update.dev.pkg = function(object="data.table", repo="https://Rdatatable.gitlab.io/data.table", field="Revision", type=getOption("pkgType"), lib=NULL, ...) {
# this works for any package, not just data.table
pkg = object
# perform package upgrade when new Revision present
stopifnot(is.character(pkg), length(pkg)==1L, !is.na(pkg),
is.character(repo), length(repo)==1L, !is.na(repo),
is.character(field), length(field)==1L, !is.na(field),
is.null(lib) || (is.character(lib) && length(lib)==1L && !is.na(lib)))
# get Revision field from remote repository PACKAGES file
una = is.na(ups<-dcf.repo(pkg, repo, field, type))
upg = una | !identical(ups, dcf.lib(pkg, field, lib.loc=lib))
if (upg) utils::install.packages(pkg, repos=repo, type=type, lib=lib, ...)
if (una) cat(sprintf("No commit information found in DESCRIPTION file for %s package. Unsure '%s' is correct field name in PACKAGES file in your devel repository '%s'.\n", pkg, field, file.path(repo, "src","contrib","PACKAGES")))
cat(sprintf("R %s package %s %s (%s)\n",
pkg,
c("is up-to-date at","has been updated to")[upg+1L],
dcf.lib(pkg, field, lib.loc=lib),
utils::packageVersion(pkg, lib.loc=lib)))
if (una)
cat(sprintf("No revision information found in DESCRIPTION file for %s package. Unsure '%s' is correct field in PACKAGES file in your package repository '%s'. Otherwise package will be re-installed every time, proceeding to installation.\n",
pkg, field, contrib.url(repo, type=type)))
# see if Revision is different then currently installed Revision, note that installed package will have Revision info only when it was installed from remote devel repo
upg = una || !identical(ups, dcf.lib(pkg, field, lib.loc=lib))
# update.dev.pkg fails on windows R 4.0.0, we have to unload package namespace before installing new version #4403
on.exit({
if (upg) {
unloadNamespace(pkg)
utils::install.packages(pkg, repos=repo, type=type, lib=lib, ...)
}
cat(sprintf("R %s package %s %s (%s)\n",
pkg,
c("is up-to-date at","has been updated to")[upg+1L],
unname(read.dcf(system.file("DESCRIPTION", package=pkg, lib.loc=lib, mustWork=TRUE), fields=field)[, field]),
utils::packageVersion(pkg, lib.loc=lib)))
})
}

# non-exported utility when using devel version #3272: data.table:::.git()
Expand Down

0 comments on commit 8b1aa6a

Please sign in to comment.