Skip to content

Commit

Permalink
Merge pull request #18 from iagomosqueira/master
Browse files Browse the repository at this point in the history
Added check.software to compare pkg versions with SOFTWARE,bib
  • Loading branch information
arni-magnusson authored Jun 9, 2024
2 parents 6e3decd + a931af6 commit f076a5c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Description: General framework to organize data, methods, and results used in
License: GPL-3
URL: https://github.com/ices-tools-prod/TAF
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(old_usage=TRUE)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(already.in.taf.library)
export(boot.dir)
export(boot.dir.inside)
export(boot.exists)
export(check.software)
export(clean)
export(clean.boot)
export(clean.data)
Expand Down
59 changes: 59 additions & 0 deletions R/check.software.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#' Check versions with those in SOFTWARE.bib
#'
#' Compare installed and required package versions
#'
#' @details
#' A SOFTWARE.bib file can be use to record what package versions a certain
#' analysis expects. Those available in the running session can be compared
#' with those listed in the file. A warning is printed if the former are
#' earlier that the later.
#'
#' @return TRUE or FALSE if available packages match those required or not.
#'
#' @name check.software
#' @rdname check.software
#'
#' @seealso [draft.software()]
#' @keywords classes
#' @export

check.software <- function() {

# GET bib file
bibfile <- (file.path(boot.dir(), "SOFTWARE.bib"))

# CHECK file exists
if(!file.exists(bibfile))
stop(paste0("File ", boot.dir(), "/SOFTWARE.bib does not exist"))

# READ bib file
entries <- taf.sources("software")

# EXTRACT versions
versions <- sapply(entries, '[[', 'version')

# COMPARE with available in session: 0 if equal, -1 is too old, 1 if newer
comparison <- unlist(lapply(setNames(nm=names(versions)), function(x)
compareVersion(as.character(packageVersion(x)), versions[x])))

# FIND those too old
toold <- comparison == -1

# WARN if any SOFTWARE.bib:versions > available
if(any(toold)) {

msg <- lapply(names(toold)[toold], function(x)
paste0(x, ": ", packageVersion(x), " installed but ", versions[x],
" required\n"))

warning(strwrap(msg, prefix="; ", initial=""))

invisible(FALSE)

} else {
invisible(TRUE)
}
}



24 changes: 24 additions & 0 deletions man/check.software.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f076a5c

Please sign in to comment.