From aeb17f7f56fa32a73caff3abb2c41796029f64cf Mon Sep 17 00:00:00 2001 From: Brice Stacey Date: Wed, 22 Apr 2026 15:40:33 -0400 Subject: [PATCH 1/2] Return description and author for installed packages Extend .ps.rpc.pkg_list to return `description` and `author` alongside the existing fields so Positron's Packages pane card view can render them. Both are normalized for display: descriptions collapse whitespace so multi-line text fits on one line, and author strips trailing `` markers from Maintainer values. All three methods (pak / base / renv) populate the new fields. base and renv share a helper that wraps utils::installed.packages() so the lib lookup only differs by `lib.loc`. See posit-dev/positron#12925 --- .../ark/src/modules/positron/packages_pane.R | 71 +++++++++++++------ 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/crates/ark/src/modules/positron/packages_pane.R b/crates/ark/src/modules/positron/packages_pane.R index 38dd3ce48..2deef3173 100644 --- a/crates/ark/src/modules/positron/packages_pane.R +++ b/crates/ark/src/modules/positron/packages_pane.R @@ -8,6 +8,49 @@ # This file contains RPC functions for the packages pane. # These functions are called via callMethod from the Positron R extension. +# Normalize a DESCRIPTION field value for display: collapse whitespace/newlines +# into single spaces so a multi-line Description fits on one line in the UI. +.ps.pkg_description_text <- function(value) { + if (is.null(value) || is.na(value)) { + return("") + } + value <- as.character(value) + value <- gsub("\\s+", " ", value, perl = TRUE) + trimws(value) +} + +# Normalize a Maintainer/Author value for display: collapse whitespace and strip +# trailing email addresses in angle brackets (e.g., "Hadley Wickham " +# becomes "Hadley Wickham"). +.ps.pkg_author_text <- function(value) { + if (is.null(value) || is.na(value)) { + return("") + } + value <- as.character(value) + value <- gsub("\\s+", " ", value, perl = TRUE) + value <- gsub("\\s*<[^>]+>", "", value, perl = TRUE) + trimws(value) +} + +# Build the package list via utils::installed.packages(), optionally scoped to a +# specific library path (used by the renv method). +.ps.pkg_list_installed <- function(lib.loc = NULL) { + ip <- utils::installed.packages( + lib.loc = lib.loc, + fields = c("Description", "Maintainer") + ) + lapply(seq_len(nrow(ip)), function(i) { + list( + id = paste0(ip[i, "Package"], "-", ip[i, "Version"]), + name = ip[i, "Package"], + displayName = ip[i, "Package"], + version = ip[i, "Version"], + description = .ps.pkg_description_text(ip[i, "Description"]), + author = .ps.pkg_author_text(ip[i, "Maintainer"]) + ) + }) +} + # Return a list of installed packages #' @export .ps.rpc.pkg_list <- function(method = c("pak", "base", "renv")) { @@ -23,32 +66,14 @@ id = paste0(pkgs$package[[i]], "-", pkgs$version[[i]]), name = pkgs$package[[i]], displayName = pkgs$package[[i]], - version = as.character(pkgs$version[[i]]) + version = as.character(pkgs$version[[i]]), + description = .ps.pkg_description_text(pkgs$description[[i]]), + author = .ps.pkg_author_text(pkgs$maintainer[[i]]) ) }) }, - base = { - ip <- utils::installed.packages() - lapply(seq_len(nrow(ip)), function(i) { - list( - id = paste0(ip[i, "Package"], "-", ip[i, "Version"]), - name = ip[i, "Package"], - displayName = ip[i, "Package"], - version = ip[i, "Version"] - ) - }) - }, - renv = { - ip <- utils::installed.packages(lib.loc = renv::paths$library()) - lapply(seq_len(nrow(ip)), function(i) { - list( - id = paste0(ip[i, "Package"], "-", ip[i, "Version"]), - name = ip[i, "Package"], - displayName = ip[i, "Package"], - version = ip[i, "Version"] - ) - }) - } + base = .ps.pkg_list_installed(), + renv = .ps.pkg_list_installed(lib.loc = renv::paths$library()) ) } From 5b45b2d93df673d318ad1982efc34ee69eeb74c5 Mon Sep 17 00:00:00 2001 From: Brice Stacey Date: Wed, 22 Apr 2026 15:58:35 -0400 Subject: [PATCH 2/2] Update crates/ark/src/modules/positron/packages_pane.R Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- crates/ark/src/modules/positron/packages_pane.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ark/src/modules/positron/packages_pane.R b/crates/ark/src/modules/positron/packages_pane.R index 2deef3173..27397e7cb 100644 --- a/crates/ark/src/modules/positron/packages_pane.R +++ b/crates/ark/src/modules/positron/packages_pane.R @@ -67,7 +67,9 @@ name = pkgs$package[[i]], displayName = pkgs$package[[i]], version = as.character(pkgs$version[[i]]), - description = .ps.pkg_description_text(pkgs$description[[i]]), + description = .ps.pkg_description_text(pkgs$description[[ + i + ]]), author = .ps.pkg_author_text(pkgs$maintainer[[i]]) ) })