Skip to content

Commit 282a50a

Browse files
chore: Remove lifecycle warnings and error on lintr checks (#321)
Co-authored-by: Toph Allen <[email protected]>
1 parent b140544 commit 282a50a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+814
-356
lines changed

.github/workflows/lint.yaml

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@ jobs:
2222

2323
- uses: r-lib/actions/setup-r-dependencies@v2
2424
with:
25-
extra-packages: any::lintr, local::.
25+
extra-packages: local::., any::lintr, any::devtools, any::testthat
2626
needs: lint
2727

2828
- name: Lint
29-
run: lintr::lint_package()
3029
shell: Rscript {0}
30+
run: |
31+
Sys.setlocale(locale = "C")
32+
devtools::load_all() # helps with object usage linter
33+
34+
package_lints <- devtools::lint(cache = FALSE)
35+
36+
# Assert that there are no lint errors
37+
if (length(package_lints) > 0) print(package_lints)
38+
testthat::expect_length(package_lints, 0)

.lintr

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
linters: linters_with_defaults(
2-
line_length_linter = line_length_linter(100)
2+
line_length_linter = line_length_linter(120L),
3+
object_name_linter = object_name_linter(styles = c("snake_case", "symbols", "CamelCase")),
4+
cyclocomp_linter = cyclocomp_linter(30L),
5+
object_length_linter(32L),
6+
indentation_linter = indentation_linter(hanging_indent_style = "tidy")
7+
)
8+
exclusions: list(
9+
"tests/testthat/2024.08.0/",
10+
"tests/testthat/2024.09.0/"
311
)

DESCRIPTION

-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ Suggests:
6161
withr
6262
VignetteBuilder:
6363
knitr
64-
RdMacros:
65-
lifecycle
6664
Encoding: UTF-8
6765
Language: en-US
6866
RoxygenNote: 7.3.2

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export(vanity_is_available)
143143
export(variant_render)
144144
export(verify_content_name)
145145
importFrom(lifecycle,deprecate_warn)
146+
importFrom(lifecycle,deprecated)
146147
importFrom(magrittr,"%>%")
147148
importFrom(rlang,"%||%")
148149
importFrom(rlang,":=")

R/audits.R

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Check to see if a vanity URL is currently in use
22
#'
3-
#' \lifecycle{experimental}
3+
#' `r lifecycle::badge('experimental')`
44
#'
55
#' @param connect A Connect R6 object
66
#' @param vanity string of the vanity URL to check
@@ -23,7 +23,7 @@ vanity_is_available <- function(connect, vanity) {
2323

2424
#' Audit R Versions
2525
#'
26-
#' \lifecycle{experimental}
26+
#' `r lifecycle::badge('experimental')`
2727
#'
2828
#' @param content `data.frame` of content information, as from [get_content()]
2929
#'
@@ -53,7 +53,10 @@ audit_r_versions <- function(content) {
5353

5454
# timeline
5555
p2 <- ggplot2::ggplot(timeline) +
56-
ggplot2::geom_point(pch = 4, ggplot2::aes(x = last_deployed_time, color = r_version, y = r_version)) +
56+
ggplot2::geom_point(
57+
pch = 4,
58+
ggplot2::aes(x = last_deployed_time, color = r_version, y = r_version)
59+
) +
5760
ggplot2::theme_minimal() +
5861
ggplot2::labs(
5962
title = "Content by Time",
@@ -67,7 +70,7 @@ audit_r_versions <- function(content) {
6770

6871
#' Audit Run As Settings
6972
#'
70-
#' \lifecycle{experimental}
73+
#' `r lifecycle::badge('experimental')`
7174
#'
7275
#' @param content `data.frame` of content information, as from [get_content()]
7376
#'
@@ -85,7 +88,7 @@ audit_runas <- function(content) {
8588
# type can be all, logged_in, acl
8689
#' Audit Access Controls
8790
#'
88-
#' \lifecycle{experimental}
91+
#' `r lifecycle::badge('experimental')`
8992
#'
9093
#' @param content `data.frame` of content information, as from [get_content()]
9194
#' @param type One of "all" or "logged_in". If "all", return a list of apps

R/connect.R

+10-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ Connect <- R6::R6Class(
6767
print = function(...) {
6868
cat("Posit Connect API Client: \n")
6969
cat(" Posit Connect Server: ", self$server, "\n", sep = "")
70-
cat(" Posit Connect API Key: ", paste0(strrep("*", 11), substr(self$api_key, nchar(self$api_key) - 3, nchar(self$api_key))), "\n", sep = "")
70+
cat(
71+
" Posit Connect API Key: ",
72+
paste0(
73+
strrep("*", 11),
74+
substr(self$api_key, nchar(self$api_key) - 3, nchar(self$api_key))
75+
),
76+
"\n",
77+
sep = ""
78+
)
7179
# TODO: something about API key... role... ?
7280
# TODO: point to docs on methods... how to see methods?
7381
cat("\n")
@@ -358,7 +366,7 @@ Connect <- R6::R6Class(
358366
count = min(page_size, .limit)
359367
)
360368
if (!is.null(filter)) {
361-
query$filter <- paste(sapply(1:length(filter), function(i) {
369+
query$filter <- paste(sapply(seq_along(filter), function(i) {
362370
sprintf("%s:%s", names(filter)[i], filter[[i]])
363371
}), collapse = .collapse)
364372
}

R/connectapi-package.R

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#' @keywords internal
2+
"_PACKAGE"
3+
4+
## usethis namespace: start
5+
#' @importFrom lifecycle deprecated
6+
## usethis namespace: end
7+
NULL

R/content.R

+52-26
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ Content <- R6::R6Class(
4545
#' @param bundle_id The bundle identifer.
4646
#' @param filename Where to write the result.
4747
#' @param overwrite Overwrite an existing filename.
48-
bundle_download = function(bundle_id, filename = tempfile(pattern = "bundle", fileext = ".tar.gz"), overwrite = FALSE) {
48+
bundle_download = function(
49+
bundle_id,
50+
filename = tempfile(pattern = "bundle", fileext = ".tar.gz"),
51+
overwrite = FALSE
52+
) {
4953
url <- v1_url("content", self$get_content()$guid, "bundles", bundle_id, "download")
5054
self$get_connect()$GET(url, httr::write_disk(filename, overwrite = overwrite), parser = "raw")
5155
return(filename)
@@ -285,7 +289,7 @@ Content <- R6::R6Class(
285289
is_rendered = function() {
286290
self$content$app_mode %in% c("rmd-static", "jupyter-static", "quarto-static")
287291
},
288-
292+
289293
#' @field is_interactive TRUE if this is a rendered content type, otherwise FALSE.
290294
is_interactive = function() {
291295
interactive_app_modes <- c(
@@ -513,7 +517,14 @@ content_title <- function(connect, guid, default = "Unknown Content") {
513517
}
514518

515519
#' @importFrom uuid UUIDgenerate
516-
content_ensure <- function(connect, name = uuid::UUIDgenerate(), title = name, guid = NULL, ..., .permitted = c("new", "existing")) {
520+
content_ensure <- function(
521+
connect,
522+
name = uuid::UUIDgenerate(),
523+
title = name,
524+
guid = NULL,
525+
...,
526+
.permitted = c("new", "existing")
527+
) {
517528
if (!is.null(guid)) {
518529
# guid-based deployment
519530
# just in case we get a 404 back...
@@ -577,7 +588,7 @@ content_ensure <- function(connect, name = uuid::UUIDgenerate(), title = name, g
577588

578589
#' Get Jobs
579590
#'
580-
#' \lifecycle{experimental} Retrieve details about jobs associated with a `content_item`.
591+
#' `r lifecycle::badge('experimental')` Retrieve details about jobs associated with a `content_item`.
581592
#' "Jobs" in Posit Connect are content executions
582593
#'
583594
#' @param content A Content object, as returned by `content_item()`
@@ -708,7 +719,7 @@ content_delete <- function(content, force = FALSE) {
708719
content_update <- function(content, ...) {
709720
validate_R6_class(content, "Content")
710721

711-
res <- content$update(...)
722+
content$update(...)
712723

713724
content$get_content_remote()
714725

@@ -747,7 +758,10 @@ content_update_owner <- function(content, owner_guid) {
747758
#' @export
748759
verify_content_name <- function(name) {
749760
if (grepl("[^\\-\\_a-zA-Z0-9]", name, perl = TRUE) || nchar(name) < 3 || nchar(name) > 64) {
750-
stop(glue::glue("ERROR: content name '{name}' must be between 3 and 64 alphanumeric characters, dashes, and underscores"))
761+
stop(glue::glue(
762+
"ERROR: content name '{name}' must be between 3 and 64 alphanumeric characters, ",
763+
"dashes, and underscores"
764+
))
751765
}
752766
return(name)
753767
}
@@ -831,7 +845,7 @@ content_add_user <- function(content, guid, role = c("viewer", "owner")) {
831845
validate_R6_class(content, "Content")
832846
role <- .define_role(role)
833847

834-
res <- purrr::map(guid, ~ .content_add_permission_impl(content, "user", .x, role))
848+
purrr::map(guid, ~ .content_add_permission_impl(content, "user", .x, role))
835849

836850
return(content)
837851
}
@@ -840,10 +854,9 @@ content_add_user <- function(content, guid, role = c("viewer", "owner")) {
840854
#' @export
841855
content_add_group <- function(content, guid, role = c("viewer", "owner")) {
842856
validate_R6_class(content, "Content")
843-
existing <- .get_permission(content, "group", guid)
844857
role <- .define_role(role)
845858

846-
res <- purrr::map(guid, ~ .content_add_permission_impl(content = content, type = "group", guid = .x, role = role))
859+
purrr::map(guid, ~ .content_add_permission_impl(content = content, type = "group", guid = .x, role = role))
847860

848861
return(content)
849862
}
@@ -885,15 +898,15 @@ content_add_group <- function(content, guid, role = c("viewer", "owner")) {
885898
#' @export
886899
content_delete_user <- function(content, guid) {
887900
validate_R6_class(content, "Content")
888-
res <- purrr::map(guid, ~ .content_delete_permission_impl(content = content, type = "user", guid = .x))
901+
purrr::map(guid, ~ .content_delete_permission_impl(content = content, type = "user", guid = .x))
889902
return(content)
890903
}
891904

892905
#' @rdname permissions
893906
#' @export
894907
content_delete_group <- function(content, guid) {
895908
validate_R6_class(content, "Content")
896-
res <- purrr::map(guid, ~ .content_delete_permission_impl(content = content, type = "group", guid = .x))
909+
purrr::map(guid, ~ .content_delete_permission_impl(content = content, type = "group", guid = .x))
897910
return(content)
898911
}
899912

@@ -957,33 +970,36 @@ get_content_permissions <- function(content, add_owner = TRUE) {
957970
}
958971

959972
#' Render a content item.
960-
#'
973+
#'
961974
#' @description Submit a request to render a content item. Once submitted, the
962975
#' server runs an asynchronous process to render the content. This might be
963976
#' useful if content needs to be updated after its source data has changed,
964977
#' especially if this doesn't happen on a regular schedule.
965-
#'
978+
#'
966979
#' Only valid for rendered content (e.g., most Quarto documents, Jupyter
967980
#' notebooks, R Markdown reports).
968-
#'
981+
#'
969982
#' @param content The content item you wish to render.
970983
#' @param variant_key If a variant key is provided, render that variant. Otherwise, render the default variant.
971984
#' @return A [VariantTask] object that can be used to track completion of the render.
972-
#'
985+
#'
973986
#' @examples
974987
#' \dontrun{
975988
#' client <- connect()
976989
#' item <- content_item(client, "951bf3ad-82d0-4bca-bba8-9b27e35c49fa")
977990
#' task <- content_render(item)
978991
#' poll_task(task)
979992
#' }
980-
#'
993+
#'
981994
#' @export
982995
content_render <- function(content, variant_key = NULL) {
983996
scoped_experimental_silence()
984997
validate_R6_class(content, "Content")
985998
if (!content$is_rendered) {
986-
stop(glue::glue("Render not supported for application mode: {content$content$app_mode}. Did you mean content_restart()?"))
999+
stop(glue::glue(
1000+
"Render not supported for application mode: {content$content$app_mode}. ",
1001+
"Did you mean content_restart()?"
1002+
))
9871003
}
9881004
if (is.null(variant_key)) {
9891005
target_variant <- get_variant(content, "default")
@@ -992,42 +1008,52 @@ content_render <- function(content, variant_key = NULL) {
9921008
}
9931009
render_task <- target_variant$render()
9941010

995-
VariantTask$new(connect = content$connect, content = content$content, key = target_variant$key, task = render_task)
1011+
VariantTask$new(
1012+
connect = content$connect,
1013+
content = content$content,
1014+
key = target_variant$key,
1015+
task = render_task
1016+
)
9961017
}
9971018

9981019
#' Restart a content item.
999-
#'
1020+
#'
10001021
#' @description Submit a request to restart a content item. Once submitted, the
10011022
#' server performs an asynchronous request to kill all processes associated with
10021023
#' the content item, starting new processes as needed. This might be useful if
10031024
#' the application relies on data that is loaded at startup, or if its memory
10041025
#' usage has grown over time.
1005-
#'
1026+
#'
10061027
#' Note that users interacting with certain types of applications may have their
10071028
#' workflows interrupted.
1008-
#'
1029+
#'
10091030
#' Only valid for interactive content (e.g., applications, APIs).
1010-
#'
1031+
#'
10111032
#' @param content The content item you wish to restart.
1012-
#'
1033+
#'
10131034
#' @examples
10141035
#' \dontrun{
10151036
#' client <- connect()
10161037
#' item <- content_item(client, "8f37d6e0-3395-4a2c-aa6a-d7f2fe1babd0")
10171038
#' content_restart(item)
10181039
#' }
1019-
#'
1040+
#'
10201041
#' @importFrom rlang :=
10211042
#' @export
10221043
content_restart <- function(content) {
10231044
validate_R6_class(content, "Content")
10241045
if (!content$is_interactive) {
1025-
stop(glue::glue("Restart not supported for application mode: {content$content$app_mode}. Did you mean content_render()?"))
1046+
stop(glue::glue(
1047+
"Restart not supported for application mode: {content$content$app_mode}. ",
1048+
"Did you mean content_render()?"
1049+
))
10261050
}
10271051
unix_epoch_in_seconds <- as.integer(Sys.time())
1028-
env_var_name <- glue::glue("_CONNECT_RESTART_{unix_epoch_in_seconds}")
1052+
# nolint start: object_usage_linter, object_name_linter
10291053
# https://rlang.r-lib.org/reference/glue-operators.html#using-glue-syntax-in-packages
1054+
env_var_name <- glue::glue("_CONNECT_RESTART_{unix_epoch_in_seconds}")
10301055
content$environment_set("{env_var_name}" := unix_epoch_in_seconds)
10311056
content$environment_set("{env_var_name}" := NA)
1057+
# nolint end
10321058
invisible(NULL)
10331059
}

R/deploy.R

+16-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ Bundle <- R6::R6Class(
2121
self$path <- path
2222
self$size <- fs::file_size(path = path)
2323
if (fs::file_exists(path) && self$size > fs::as_fs_bytes(max_bundle_size)) {
24-
warning(glue::glue("Bundle size is greater than {max_bundle_size}. Please ensure your bundle is not including too much."))
24+
warning(glue::glue(
25+
"Bundle size is greater than {max_bundle_size}. ",
26+
"Please ensure your bundle is not including too much."
27+
))
2528
}
2629
},
2730

@@ -302,7 +305,12 @@ bundle_path <- function(path) {
302305
#'
303306
#' @family deployment functions
304307
#' @export
305-
download_bundle <- function(content, filename = fs::file_temp(pattern = "bundle", ext = ".tar.gz"), bundle_id = NULL, overwrite = FALSE) {
308+
download_bundle <- function(
309+
content,
310+
filename = fs::file_temp(pattern = "bundle", ext = ".tar.gz"),
311+
bundle_id = NULL,
312+
overwrite = FALSE
313+
) {
306314
validate_R6_class(content, "Content")
307315

308316
from_content <- content$get_content_remote()
@@ -345,7 +353,8 @@ download_bundle <- function(content, filename = fs::file_temp(pattern = "bundle"
345353
#' @param title optional The title to be used for the content on the server
346354
#' @param guid optional The GUID if the content already exists on the server
347355
#' @param ... Additional arguments passed along to the content creation
348-
#' @param .pre_deploy An expression to execute before deploying the new bundle. The variables `content` and `bundle_id` are supplied
356+
#' @param .pre_deploy An expression to execute before deploying the new bundle.
357+
#' The variables `content` and `bundle_id` are supplied
349358
#' @param content A Content object
350359
#'
351360
#' @return Task A task object
@@ -382,7 +391,10 @@ deploy <- function(connect, bundle, name = create_random_name(), title = name, g
382391
new_bundle_id <- con$content_upload(bundle_path = bundle$path, guid = content$guid)[["id"]]
383392

384393
pre_deploy_expr <- rlang::enexpr(.pre_deploy)
385-
rlang::eval_bare(pre_deploy_expr, env = rlang::env(content = content_item(con, content$guid), bundle_id = new_bundle_id))
394+
rlang::eval_bare(
395+
pre_deploy_expr,
396+
env = rlang::env(content = content_item(con, content$guid), bundle_id = new_bundle_id)
397+
)
386398

387399
message("Deploying bundle")
388400
# deploy

0 commit comments

Comments
 (0)