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) {