From 4204091831242bf55ace0c6ea47b1e96fbc079d7 Mon Sep 17 00:00:00 2001 From: "Jennifer (Jenny) Bryan" Date: Fri, 15 Nov 2024 08:45:27 -0800 Subject: [PATCH] Expose package version info (#625) * Expose package version info * Respond to review --- crates/ark/src/modules/positron/package.R | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/ark/src/modules/positron/package.R b/crates/ark/src/modules/positron/package.R index 105f6743c..dc10bdb04 100644 --- a/crates/ark/src/modules/positron/package.R +++ b/crates/ark/src/modules/positron/package.R @@ -21,6 +21,29 @@ #' @export .ps.rpc.is_installed <- .ps.is_installed +# Returns a list containing: +# * the version string if the package is installed and NULL otherwise +# * a logical indicating if package is installed at or above the minimum version +# This may seem weird, but it's impractical for positron-r to do version +# comparisons. +#' @export +.ps.rpc.packageVersion <- function(pkg, minimumVersion = NULL) { + installed <- system.file(package = pkg) != "" + + if (installed) { + version <- utils::packageVersion(pkg) + list( + version = as.character(version), + compatible = is.null(minimumVersion) || version >= minimumVersion + ) + } else { + list( + version = NULL, + compatible = FALSE + ) + } +} + #' @export .ps.rpc.install_packages <- function(packages) { for (pkg in packages) {