From 5458fdfb61be0526a875dc79c276ea61deee9863 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 13 Nov 2024 13:38:17 -0800 Subject: [PATCH 1/2] Expose package version info --- crates/ark/src/modules/positron/package.R | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/ark/src/modules/positron/package.R b/crates/ark/src/modules/positron/package.R index 105f6743c..47d5bb285 100644 --- a/crates/ark/src/modules/positron/package.R +++ b/crates/ark/src/modules/positron/package.R @@ -21,6 +21,32 @@ #' @export .ps.rpc.is_installed <- .ps.is_installed +# Returns a list containing: +# * the version string if the package is installed and NULL otherwise +# * a minimum version to check for, with '0.0.0' as a dummy default +# * 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, checkAgainst = "0.0.0") { + installed <- system.file(package = pkg) != "" + + if (installed) { + version <- utils::packageVersion(pkg) + list( + version = as.character(version), + checkAgainst = as.character(checkAgainst), + checkResult = version >= checkAgainst + ) + } else { + list( + version = NULL, + checkAgainst = as.character(checkAgainst), + checkResult = FALSE + ) + } +} + #' @export .ps.rpc.install_packages <- function(packages) { for (pkg in packages) { From 78e71dc6589bb3ee5e3a6848e5dd50afde0e7411 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Thu, 14 Nov 2024 12:56:31 -0800 Subject: [PATCH 2/2] Respond to review --- crates/ark/src/modules/positron/package.R | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/ark/src/modules/positron/package.R b/crates/ark/src/modules/positron/package.R index 47d5bb285..dc10bdb04 100644 --- a/crates/ark/src/modules/positron/package.R +++ b/crates/ark/src/modules/positron/package.R @@ -23,26 +23,23 @@ # Returns a list containing: # * the version string if the package is installed and NULL otherwise -# * a minimum version to check for, with '0.0.0' as a dummy default # * 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, checkAgainst = "0.0.0") { +.ps.rpc.packageVersion <- function(pkg, minimumVersion = NULL) { installed <- system.file(package = pkg) != "" if (installed) { version <- utils::packageVersion(pkg) list( - version = as.character(version), - checkAgainst = as.character(checkAgainst), - checkResult = version >= checkAgainst + version = as.character(version), + compatible = is.null(minimumVersion) || version >= minimumVersion ) } else { list( - version = NULL, - checkAgainst = as.character(checkAgainst), - checkResult = FALSE + version = NULL, + compatible = FALSE ) } }