diff --git a/DESCRIPTION b/DESCRIPTION index 2f045f6..ad04dba 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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) diff --git a/NAMESPACE b/NAMESPACE index 3c61c3b..d87ac14 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/check.software.R b/R/check.software.R new file mode 100644 index 0000000..91f3304 --- /dev/null +++ b/R/check.software.R @@ -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) + } +} + + + diff --git a/man/check.software.Rd b/man/check.software.Rd new file mode 100644 index 0000000..25adfad --- /dev/null +++ b/man/check.software.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/check.software.R +\name{check.software} +\alias{check.software} +\title{Check versions with those in SOFTWARE.bib} +\usage{ +check.software() +} +\value{ +TRUE or FALSE if available packages match those required or not. +} +\description{ +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. +} +\seealso{ +[draft.software()] +} +\keyword{classes}