From 57f5519850294671cb5f4022097c7e1631b97242 Mon Sep 17 00:00:00 2001 From: Toph Allen Date: Thu, 16 Oct 2025 14:45:35 -0400 Subject: [PATCH 1/5] add functions to convert content lists to data frames --- DESCRIPTION | 2 +- NAMESPACE | 2 + R/content.R | 49 ++++++++++++++++++++++- man/VariantR6.Rd | 14 ++----- man/VariantSchedule.Rd | 1 - man/VariantTask.Rd | 1 - man/as.data.frame.connect_content_list.Rd | 23 +++++++++++ man/as_tibble.connect_content_list.Rd | 19 +++++++++ 8 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 man/as.data.frame.connect_content_list.Rd create mode 100644 man/as_tibble.connect_content_list.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 88c906ae..48f1d628 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -64,7 +64,7 @@ VignetteBuilder: knitr Encoding: UTF-8 Language: en-US -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 Roxygen: list(markdown = TRUE) Config/testthat/edition: 3 Collate: diff --git a/NAMESPACE b/NAMESPACE index c04ae9b2..65d159df 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,9 +5,11 @@ S3method("[",connect_tag_tree) S3method("[[",connect_tag_tree) S3method(api_build,op_base_connect) S3method(api_build,op_head) +S3method(as.data.frame,connect_content_list) S3method(as.data.frame,connect_integration_list) S3method(as.data.frame,connect_list_hits) S3method(as.data.frame,tbl_connect) +S3method(as_tibble,connect_content_list) S3method(as_tibble,connect_integration_list) S3method(as_tibble,connect_list_hits) S3method(connect_vars,op_base) diff --git a/R/content.R b/R/content.R index f3a1eef6..42822f3c 100644 --- a/R/content.R +++ b/R/content.R @@ -1504,7 +1504,7 @@ get_content_packages <- function(content) { #' usually not what you want. #' #' @return -#' A list of [Content] objects. +#' A list of [Content] objects, of class "connect_content_list" #' #' @details #' Please see https://docs.posit.co/connect/api/#get-/v1/search/content for more @@ -1548,9 +1548,12 @@ search_content <- function( limit = limit ) - purrr::map(res, function(x) { + content_list <- purrr::map(res, function(x) { Content$new(client, x) }) + + class(content_list) <- c("connect_content_list", class(content_list)) + content_list } .search_content <- function( @@ -1573,3 +1576,45 @@ search_content <- function( client$GET(path, query = query) } + +#' Convert content list to a data frame +#' +#' @description +#' Converts a list returned by [search_content()] into a data frame. +#' +#' @param x A `connect_content_list` object (from [search_content()]). +#' @param row.names Passed to [base::as.data.frame()]. +#' @param optional Passed to [base::as.data.frame()]. +#' @param ... Passed to [base::as.data.frame()]. +#' +#' @return A `data.frame` with one row per content item. +#' @export +as.data.frame.connect_content_list <- function( + x, + row.names = NULL, # nolint + optional = FALSE, + ... +) { + content_tbl <- as_tibble(x) + as.data.frame( + content_tbl, + row.names = row.names, + optional = optional, + ... + ) +} + +#' Convert integration list to a tibble +#' +#' @description +#' Converts a list returned by [search_content()] to a tibble. +#' +#' @param x A `connect_content_list` object. +#' @param ... Unused. +#' +#' @return A tibble with one row per content item. +#' @export +as_tibble.connect_content_list <- function(x, ...) { + content_data <- purrr::map(x, "content") + parse_connectapi_typed(content_data, connectapi_ptypes$content) +} diff --git a/man/VariantR6.Rd b/man/VariantR6.Rd index be0cc4a6..cdf922d6 100644 --- a/man/VariantR6.Rd +++ b/man/VariantR6.Rd @@ -39,7 +39,6 @@ Other R6 classes: \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-Variant-get_variant}{\code{Variant$get_variant()}} \item \href{#method-Variant-get_variant_remote}{\code{Variant$get_variant_remote()}} \item \href{#method-Variant-new}{\code{Variant$new()}} \item \href{#method-Variant-send_mail}{\code{Variant$send_mail()}} @@ -90,19 +89,12 @@ Other R6 classes: }} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Variant-get_variant}{}}} -\subsection{Method \code{get_variant()}}{ -Get the underlying variant data. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Variant$get_variant()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Variant-get_variant_remote}{}}} \subsection{Method \code{get_variant_remote()}}{ +Get the underlying variant data. + + Get and store the (remote) variant data. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{Variant$get_variant_remote()}\if{html}{\out{
}} diff --git a/man/VariantSchedule.Rd b/man/VariantSchedule.Rd index ee961e1a..d7c23e29 100644 --- a/man/VariantSchedule.Rd +++ b/man/VariantSchedule.Rd @@ -81,7 +81,6 @@ Other R6 classes:
  • connectapi::Variant$get_subscribers()
  • connectapi::Variant$get_url()
  • connectapi::Variant$get_url_rev()
  • -
  • connectapi::Variant$get_variant()
  • connectapi::Variant$get_variant_remote()
  • connectapi::Variant$job()
  • connectapi::Variant$jobs()
  • diff --git a/man/VariantTask.Rd b/man/VariantTask.Rd index 4f23bd9e..316a53a1 100644 --- a/man/VariantTask.Rd +++ b/man/VariantTask.Rd @@ -80,7 +80,6 @@ Other R6 classes:
  • connectapi::Variant$get_subscribers()
  • connectapi::Variant$get_url()
  • connectapi::Variant$get_url_rev()
  • -
  • connectapi::Variant$get_variant()
  • connectapi::Variant$get_variant_remote()
  • connectapi::Variant$job()
  • connectapi::Variant$jobs()
  • diff --git a/man/as.data.frame.connect_content_list.Rd b/man/as.data.frame.connect_content_list.Rd new file mode 100644 index 00000000..5f958dfd --- /dev/null +++ b/man/as.data.frame.connect_content_list.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/content.R +\name{as.data.frame.connect_content_list} +\alias{as.data.frame.connect_content_list} +\title{Convert content list to a data frame} +\usage{ +\method{as.data.frame}{connect_content_list}(x, row.names = NULL, optional = FALSE, ...) +} +\arguments{ +\item{x}{A \code{connect_content_list} object (from \code{\link[=search_content]{search_content()}}).} + +\item{row.names}{Passed to \code{\link[base:as.data.frame]{base::as.data.frame()}}.} + +\item{optional}{Passed to \code{\link[base:as.data.frame]{base::as.data.frame()}}.} + +\item{...}{Passed to \code{\link[base:as.data.frame]{base::as.data.frame()}}.} +} +\value{ +A \code{data.frame} with one row per content item. +} +\description{ +Converts a list returned by \code{\link[=search_content]{search_content()}} into a data frame. +} diff --git a/man/as_tibble.connect_content_list.Rd b/man/as_tibble.connect_content_list.Rd new file mode 100644 index 00000000..ff6147e2 --- /dev/null +++ b/man/as_tibble.connect_content_list.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/content.R +\name{as_tibble.connect_content_list} +\alias{as_tibble.connect_content_list} +\title{Convert integration list to a tibble} +\usage{ +\method{as_tibble}{connect_content_list}(x, ...) +} +\arguments{ +\item{x}{A \code{connect_content_list} object.} + +\item{...}{Unused.} +} +\value{ +A tibble with one row per content item. +} +\description{ +Converts a list returned by \code{\link[=search_content]{search_content()}} to a tibble. +} From a4db014da539b64c3f6d2fe663b4d2de031f4a1c Mon Sep 17 00:00:00 2001 From: Toph Allen Date: Thu, 16 Oct 2025 14:50:01 -0400 Subject: [PATCH 2/5] test data frame conversion. --- tests/testthat/test-content.R | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/testthat/test-content.R b/tests/testthat/test-content.R index 1aa56df1..563f551d 100644 --- a/tests/testthat/test-content.R +++ b/tests/testthat/test-content.R @@ -536,6 +536,58 @@ with_mock_dir("2025.09.0", { ) ) }) + + test_that("search_content() can be converted to a data frame correctly", { + content_df <- search_content(client, q = "sea bream") |> + as_tibble() + expect_named( + content_df, + c( + "guid", + "name", + "title", + "description", + "access_type", + "connection_timeout", + "read_timeout", + "init_timeout", + "idle_timeout", + "max_processes", + "min_processes", + "max_conns_per_process", + "load_factor", + "created_time", + "last_deployed_time", + "bundle_id", + "app_mode", + "content_category", + "parameterized", + "cluster_name", + "image_name", + "r_version", + "py_version", + "quarto_version", + "run_as", + "run_as_current_user", + "owner_guid", + "content_url", + "dashboard_url", + "app_role", + "vanity_url", + "id", + "owner", + "tags" + ) + ) + expect_equal( + content_df$title, + c("sea bream report", "sea bream dashboard") + ) + expect_equal( + content_df$guid, + c("c9f68287", "53032a0e") + ) + }) }) test_that("content search errors on Connect < 2024.04.0", { From 0cf14ea80c898e3f59a6688448806ca926ee1515 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 16 Oct 2025 18:59:16 +0000 Subject: [PATCH 3/5] Update documentation --- man/search_content.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/search_content.Rd b/man/search_content.Rd index b84636e6..531fd25a 100644 --- a/man/search_content.Rd +++ b/man/search_content.Rd @@ -33,7 +33,7 @@ for pagination, but all subsequent pages will still be fetched. This is usually not what you want.} } \value{ -A list of \link{Content} objects. +A list of \link{Content} objects, of class "connect_content_list" } \description{ Search for content on the Connect server From a8f4294404ede9727778076c2ea8d5f7bc4e74fc Mon Sep 17 00:00:00 2001 From: Toph Allen Date: Thu, 16 Oct 2025 18:28:38 -0400 Subject: [PATCH 4/5] revert roxygennote to 7.3.2 --- DESCRIPTION | 4 ++-- man/bundle_dir.Rd | 2 +- man/bundle_path.Rd | 2 +- man/bundle_static.Rd | 2 +- man/connect.Rd | 2 +- man/deploy.Rd | 2 +- man/search_content.Rd | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 48f1d628..eea23ca4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -64,10 +64,10 @@ VignetteBuilder: knitr Encoding: UTF-8 Language: en-US -RoxygenNote: 7.3.3 +RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) Config/testthat/edition: 3 -Collate: +Collate: 'audits.R' 'browse.R' 'connect.R' diff --git a/man/bundle_dir.Rd b/man/bundle_dir.Rd index 47d7c865..272fd84a 100644 --- a/man/bundle_dir.Rd +++ b/man/bundle_dir.Rd @@ -21,7 +21,7 @@ Bundle A bundle object Creates a bundle from a target directory. } \examples{ -\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf} +\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} bundle_dir(system.file("tests/testthat/examples/shiny/", package = "connectapi")) \dontshow{\}) # examplesIf} diff --git a/man/bundle_path.Rd b/man/bundle_path.Rd index 586e0d11..7eff4f3c 100644 --- a/man/bundle_path.Rd +++ b/man/bundle_path.Rd @@ -16,7 +16,7 @@ Bundle A bundle object Define a bundle from a path (a path directly to a tar.gz file) } \examples{ -\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf} +\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} bundle_path(system.file("tests/testthat/examples/static.tar.gz", package = "connectapi")) \dontshow{\}) # examplesIf} diff --git a/man/bundle_static.Rd b/man/bundle_static.Rd index 0a755959..bc855f14 100644 --- a/man/bundle_static.Rd +++ b/man/bundle_static.Rd @@ -26,7 +26,7 @@ directory, generates a basic manifest file (using the first file as the NOTE: the \code{rsconnect} package is required for this function to work properly. } \examples{ -\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf} +\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} bundle_static(system.file("logo.png", package = "connectapi")) \dontshow{\}) # examplesIf} diff --git a/man/connect.Rd b/man/connect.Rd index c0b68c18..70c3fd7a 100644 --- a/man/connect.Rd +++ b/man/connect.Rd @@ -75,7 +75,7 @@ fallback_key <- Sys.getenv("VIEWER_ROLE_API_KEY") client <- connect(token = token, token_local_testing_key = fallback_key) } -\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf} +\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # default is to read CONNECT_SERVER and CONNECT_API_KEY environment variables # this example will read TEST_1_SERVER and TEST_1_API_KEY diff --git a/man/deploy.Rd b/man/deploy.Rd index 394ce63a..b126c199 100644 --- a/man/deploy.Rd +++ b/man/deploy.Rd @@ -60,7 +60,7 @@ bnd <- bundle_dir(".") deploy(client, bnd) } -\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf} +\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} client <- connect(prefix = "TEST_1") bnd <- bundle_path(system.file("tests/testthat/examples/static.tar.gz", package = "connectapi")) diff --git a/man/search_content.Rd b/man/search_content.Rd index b84636e6..531fd25a 100644 --- a/man/search_content.Rd +++ b/man/search_content.Rd @@ -33,7 +33,7 @@ for pagination, but all subsequent pages will still be fetched. This is usually not what you want.} } \value{ -A list of \link{Content} objects. +A list of \link{Content} objects, of class "connect_content_list" } \description{ Search for content on the Connect server From 62ef6ba780df11144c583c0fe3dfec6a662b9c3e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 16 Oct 2025 22:32:57 +0000 Subject: [PATCH 5/5] Update documentation --- man/bundle_dir.Rd | 2 +- man/bundle_path.Rd | 2 +- man/bundle_static.Rd | 2 +- man/connect.Rd | 2 +- man/deploy.Rd | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/man/bundle_dir.Rd b/man/bundle_dir.Rd index 272fd84a..47d7c865 100644 --- a/man/bundle_dir.Rd +++ b/man/bundle_dir.Rd @@ -21,7 +21,7 @@ Bundle A bundle object Creates a bundle from a target directory. } \examples{ -\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf} bundle_dir(system.file("tests/testthat/examples/shiny/", package = "connectapi")) \dontshow{\}) # examplesIf} diff --git a/man/bundle_path.Rd b/man/bundle_path.Rd index 7eff4f3c..586e0d11 100644 --- a/man/bundle_path.Rd +++ b/man/bundle_path.Rd @@ -16,7 +16,7 @@ Bundle A bundle object Define a bundle from a path (a path directly to a tar.gz file) } \examples{ -\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf} bundle_path(system.file("tests/testthat/examples/static.tar.gz", package = "connectapi")) \dontshow{\}) # examplesIf} diff --git a/man/bundle_static.Rd b/man/bundle_static.Rd index bc855f14..0a755959 100644 --- a/man/bundle_static.Rd +++ b/man/bundle_static.Rd @@ -26,7 +26,7 @@ directory, generates a basic manifest file (using the first file as the NOTE: the \code{rsconnect} package is required for this function to work properly. } \examples{ -\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf} bundle_static(system.file("logo.png", package = "connectapi")) \dontshow{\}) # examplesIf} diff --git a/man/connect.Rd b/man/connect.Rd index 70c3fd7a..c0b68c18 100644 --- a/man/connect.Rd +++ b/man/connect.Rd @@ -75,7 +75,7 @@ fallback_key <- Sys.getenv("VIEWER_ROLE_API_KEY") client <- connect(token = token, token_local_testing_key = fallback_key) } -\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf} # default is to read CONNECT_SERVER and CONNECT_API_KEY environment variables # this example will read TEST_1_SERVER and TEST_1_API_KEY diff --git a/man/deploy.Rd b/man/deploy.Rd index b126c199..394ce63a 100644 --- a/man/deploy.Rd +++ b/man/deploy.Rd @@ -60,7 +60,7 @@ bnd <- bundle_dir(".") deploy(client, bnd) } -\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf} client <- connect(prefix = "TEST_1") bnd <- bundle_path(system.file("tests/testthat/examples/static.tar.gz", package = "connectapi"))