From a827194699d28fd0d9287f4c1681e08c2352c062 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Fri, 19 Apr 2024 09:19:47 -0400 Subject: [PATCH 1/7] Move dplyr to Suggests --- DESCRIPTION | 2 +- NAMESPACE | 3 --- R/connectapi.R | 5 +++++ R/get.R | 21 +++++++++++---------- R/lazy.R | 5 ++--- R/tags.R | 4 ++-- R/utils-collect.R | 10 ---------- man/collect.Rd | 9 --------- tests/integrated/test-lazy.R | 2 ++ 9 files changed, 23 insertions(+), 38 deletions(-) delete mode 100644 R/utils-collect.R delete mode 100644 man/collect.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 884c4891..b98d919e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,6 @@ License: MIT + file LICENSE URL: https://pkgs.rstudio.com/connectapi/, https://github.com/rstudio/connectapi BugReports: https://github.com/rstudio/connectapi/issues Imports: - dplyr, fs, glue, httr, @@ -41,6 +40,7 @@ Suggests: crayon, dbplyr, devtools, + dplyr, flexdashboard, ggplot2, gridExtra, diff --git a/NAMESPACE b/NAMESPACE index 6bc35558..e945621f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,7 +6,6 @@ S3method("[[",connect_tag_tree) S3method(api_build,op_base_connect) S3method(api_build,op_head) S3method(as.data.frame,tbl_connect) -S3method(collect,tbl_connect) S3method(connect_vars,op_base) S3method(connect_vars,op_single) S3method(connect_vars,tbl_connect) @@ -37,7 +36,6 @@ export(bundle_dir) export(bundle_path) export(bundle_static) export(cache_apps) -export(collect) export(connect) export(content_add_group) export(content_add_user) @@ -135,7 +133,6 @@ export(user_guid_from_username) export(users_create_remote) export(variant_render) export(verify_content_name) -importFrom(dplyr,collect) importFrom(lifecycle,deprecate_warn) importFrom(magrittr,"%>%") importFrom(rlang,"%||%") diff --git a/R/connectapi.R b/R/connectapi.R index 30f49d57..2aba5a5b 100644 --- a/R/connectapi.R +++ b/R/connectapi.R @@ -22,3 +22,8 @@ utils::globalVariables( ) current_connect_version <- "2024.03.0" + +.onLoad <- function(...) { + vctrs::s3_register("dplyr::collect", "tbl_connect") + invisible() +} diff --git a/R/get.R b/R/get.R index 7323a43c..ac7625f7 100644 --- a/R/get.R +++ b/R/get.R @@ -334,9 +334,13 @@ content_list_with_permissions <- function(src, ..., .p = NULL) { content_list <- get_content(src, .p = .p) message("Getting permission list") - pb <- progress::progress_bar$new(total = nrow(content_list), format = "[:bar] :percent :eta") - updated_list <- content_list %>% dplyr::mutate( - permission = purrr::map(guid, function(.x) .get_content_permission_with_progress(src, .x, pb)) + pb <- progress::progress_bar$new( + total = nrow(content_list), + format = "[:bar] :percent :eta" + ) + updated_list[["permission"]] <- purrr::map( + content_list$guid, + function(.x) .get_content_permission_with_progress(src, .x, pb) ) return(updated_list) @@ -367,13 +371,10 @@ content_list_by_tag <- function(src, tag) { #' @export content_list_guid_has_access <- function(content_list, guid) { warn_experimental("content_list_filter_by_guid") - filtered <- content_list %>% dplyr::filter( - access_type == "all" | - access_type == "logged_in" | - owner_guid == {{ guid }} | - purrr::map_lgl(permission, ~ {{ guid }} %in% .x$principal_guid) - ) - return(filtered) + row_filter <- content_list$access_type %in% c("all", "logged_in") | + content_list$owner_guid == guid | + purrr::map_lgl(content_list$permission, ~ guid %in% .x$principal_guid) + content_list[row_filter, ] } #' Get usage information for deployed shiny applications diff --git a/R/lazy.R b/R/lazy.R index 3c421699..fc43b422 100644 --- a/R/lazy.R +++ b/R/lazy.R @@ -36,8 +36,7 @@ tbl_connect <- function(src, from = c("users", "groups", "content", "usage_shiny dplyr::make_tbl(c("connect", "lazy"), src = src, ops = ops) } -#' @importFrom dplyr collect -#' @export +# This will be registered in .onLoad is dplyr is available collect.tbl_connect <- function(x, ..., n = Inf) { api_build(op = x[["ops"]], con = x[["src"]], n = n) } @@ -96,7 +95,7 @@ print.tbl_connect <- function(x, ..., n = NULL) { #' @export as.data.frame.tbl_connect <- function(x, row.names = NULL, optional = NULL, ..., n = Inf) { - as.data.frame(collect(x, n = n)) + as.data.frame(dplyr::collect(x, n = n)) } op_base_connect <- function(x, vars) { diff --git a/R/tags.R b/R/tags.R index 0fcd1da2..c913da03 100644 --- a/R/tags.R +++ b/R/tags.R @@ -435,7 +435,7 @@ tag_tree <- function(.x) { parse_tags_tbl <- function(x) { parsed_tags <- purrr::map_dfr(x, ~ { - out <- dplyr::tibble( + out <- tibble::tibble( id = as.character(.x$id), name = .x$name, created_time = .x$created_time, @@ -445,7 +445,7 @@ parse_tags_tbl <- function(x) { if (length(.x$children) > 0) { child <- parse_tags_tbl(.x$children) - out <- dplyr::bind_rows(out, child) + out <- rbind(out, child) } return(out) diff --git a/R/utils-collect.R b/R/utils-collect.R deleted file mode 100644 index 7aab99a8..00000000 --- a/R/utils-collect.R +++ /dev/null @@ -1,10 +0,0 @@ -#' Collect function -#' -#' See \code{dplyr::\link[dplyr:collect]{collect}} for details. -#' -#' @name collect -#' @rdname collect -#' @keywords internal -#' @export -#' @importFrom dplyr collect -NULL diff --git a/man/collect.Rd b/man/collect.Rd deleted file mode 100644 index 490e5aaa..00000000 --- a/man/collect.Rd +++ /dev/null @@ -1,9 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils-collect.R -\name{collect} -\alias{collect} -\title{Collect function} -\description{ -See \code{dplyr::\link[dplyr:collect]{collect}} for details. -} -\keyword{internal} diff --git a/tests/integrated/test-lazy.R b/tests/integrated/test-lazy.R index 99cd9ae6..618c4f83 100644 --- a/tests/integrated/test-lazy.R +++ b/tests/integrated/test-lazy.R @@ -1,3 +1,5 @@ +testthat::skip_if_not_installed("dbplyr") + # should connect with env vars test_conn_1 <- connect(prefix = "TEST_1") test_conn_2 <- connect(prefix = "TEST_2") From 071afcd278ed6b7588ef8fcd03e9ba3c56821d8e Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Fri, 19 Apr 2024 09:30:06 -0400 Subject: [PATCH 2/7] Oops --- R/get.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/get.R b/R/get.R index ac7625f7..713a6a0d 100644 --- a/R/get.R +++ b/R/get.R @@ -338,12 +338,12 @@ content_list_with_permissions <- function(src, ..., .p = NULL) { total = nrow(content_list), format = "[:bar] :percent :eta" ) - updated_list[["permission"]] <- purrr::map( + content_list[["permission"]] <- purrr::map( content_list$guid, function(.x) .get_content_permission_with_progress(src, .x, pb) ) - return(updated_list) + content_list } #' Content List From facdb61db85e7dfd6ec00fb249a8985d7312b4c3 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Fri, 19 Apr 2024 09:44:29 -0400 Subject: [PATCH 3/7] Add to news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 43f3f1a9..c794fcff 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,8 @@ - `Content$tag_delete()` removes the tag from the target content item rather than removing the tag entirely. (#194) - Fix issue with `NULL` or `length 1` job outputs ([#193](https://github.com/rstudio/connectapi/issues/193)) +- BREAKING: dplyr is no longer a required dependency. If you use `tbl_connect()`, + you will need to install dplyr and dbplyr explicitly. # connectapi 0.1.3.1 From 2db62e0fe38d7474ba9265246706ad2e7a278983 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Fri, 19 Apr 2024 13:32:13 -0400 Subject: [PATCH 4/7] Update R/get.R Co-authored-by: Jonathan Keane --- R/get.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/get.R b/R/get.R index 713a6a0d..45868c91 100644 --- a/R/get.R +++ b/R/get.R @@ -371,10 +371,10 @@ content_list_by_tag <- function(src, tag) { #' @export content_list_guid_has_access <- function(content_list, guid) { warn_experimental("content_list_filter_by_guid") - row_filter <- content_list$access_type %in% c("all", "logged_in") | + rows_keep <- content_list$access_type %in% c("all", "logged_in") | content_list$owner_guid == guid | purrr::map_lgl(content_list$permission, ~ guid %in% .x$principal_guid) - content_list[row_filter, ] + content_list[rows_keep, ] } #' Get usage information for deployed shiny applications From 7b4e1a68bb857745e791e6ad74d0db683c890c0c Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Fri, 19 Apr 2024 13:32:23 -0400 Subject: [PATCH 5/7] Update R/lazy.R Co-authored-by: Jonathan Keane --- R/lazy.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/lazy.R b/R/lazy.R index fc43b422..2705e5d5 100644 --- a/R/lazy.R +++ b/R/lazy.R @@ -36,7 +36,7 @@ tbl_connect <- function(src, from = c("users", "groups", "content", "usage_shiny dplyr::make_tbl(c("connect", "lazy"), src = src, ops = ops) } -# This will be registered in .onLoad is dplyr is available +# This will be registered in .onLoad if dplyr is available collect.tbl_connect <- function(x, ..., n = Inf) { api_build(op = x[["ops"]], con = x[["src"]], n = n) } From 49978e445e804ea9cbbc3f04a9d2ed90ce9ce1e2 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Fri, 19 Apr 2024 13:33:32 -0400 Subject: [PATCH 6/7] Update R/lazy.R --- R/lazy.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/lazy.R b/R/lazy.R index 2705e5d5..11750c48 100644 --- a/R/lazy.R +++ b/R/lazy.R @@ -95,6 +95,9 @@ print.tbl_connect <- function(x, ..., n = NULL) { #' @export as.data.frame.tbl_connect <- function(x, row.names = NULL, optional = NULL, ..., n = Inf) { + # We don't need to check if dplyr is available here + # because you won't have a tbl_connect without first + # checking for dplyr. as.data.frame(dplyr::collect(x, n = n)) } From 94e5b07b87493dade742f4312b1b043d5bc03476 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Fri, 19 Apr 2024 13:40:07 -0400 Subject: [PATCH 7/7] Update NEWS --- NEWS.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index c794fcff..fe3704dd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,10 +2,14 @@ ## Breaking changes +- All previously deprecated functions are now removed. - The functions `Connect$download_bundle()` and `Connect$bundle_delete()` have been removed. Use `Content$bundle_download()` and `Content$bundle_delete()` instead. -- All previously deprecated functions are now removed. +- dplyr is no longer a required dependency. If you use `tbl_connect()`, + you will need to install dplyr and dbplyr explicitly. (#246) + +## Enhancements and fixes - The package is now tested against many versions of Connect, back to 1.8.8.2 (May 2021). There are now fewer warnings about version mismatches: you should only see a warning if your Connect server is older than that. (#244) @@ -14,8 +18,7 @@ - `Content$tag_delete()` removes the tag from the target content item rather than removing the tag entirely. (#194) - Fix issue with `NULL` or `length 1` job outputs ([#193](https://github.com/rstudio/connectapi/issues/193)) -- BREAKING: dplyr is no longer a required dependency. If you use `tbl_connect()`, - you will need to install dplyr and dbplyr explicitly. + # connectapi 0.1.3.1