Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add using_posit_connect() to check for Posit Connect environments #11

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export(using_nix_shell)
export(using_option)
export(using_os)
export(using_podman_container)
export(using_posit_connect)
export(using_r_version)
export(using_rstudio)
export(using_rstudio_dark_theme)
Expand Down
22 changes: 21 additions & 1 deletion R/rstudio.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @title RStudio environments
#' @description
#' These functions enable you to determine whether code is being run in the
#' presence of various features of the RStudio IDE.
#' presence of various features of the RStudio IDE and other Posit products.
#'
#' `using_rstudio()` determines whether code is being run in
#' RStudio
Expand Down Expand Up @@ -41,3 +41,23 @@ using_rstudio_dark_theme <- function() {
FALSE
}
}

#' @noRd
#' @description `using_rstudio_product()` checks whether or not the
#' `RSTUDIO_PRODUCT` environment variable is set
#' @param name Optional name of a particular product
using_rstudio_product <- function(name = NULL) {
using_envvar("RSTUDIO_PRODUCT", value = name)
}

#' @rdname rstudio
#' @description `using_posit_connect()` checks whether [Posit Connect]() is
#' being used
#' @seealso https://docs.posit.co/connect/user/content-settings/#content-vars
#'
#' @export
#' @examples
#' using_posit_connect()
using_posit_connect <- function() {
using_rstudio_product(name = "CONNECT")
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ reference:
contents:
- using_r_version
- using_rstudio
- using_posit_connect
- using_rstudio_jobs
- using_rstudio_dark_theme
- using_vscode
Expand Down
12 changes: 11 additions & 1 deletion man/rstudio.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tests/testthat/test-rstudio.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,25 @@ test_that("using_rstudio_jobs() works as expected", {
test_that("using_rstudio_dark_theme() returns a boolean", {
expect_true(is.logical(using_rstudio_dark_theme()))
})

test_that("using_rstudio_product validates input properly", {
expect_error(using_rstudio_product(name = NA_character_))
expect_error(using_rstudio_product(name = 1))
expect_error(using_rstudio_product(name = FALSE))
expect_error(using_rstudio_product(name = c("CONNECT", "WORKBENCH")))
})

test_that("using_rstudio_product works as expected when `RSTUDIO_PRODUCT` not set", { # nolint: line_length_linter
withr::local_envvar(list("USING_RSTUDIO_PRODUCT" = NA))
expect_false(using_rstudio_product())
expect_false(using_rstudio_product(name = "CONNECT"))
expect_false(using_posit_connect())
})

test_that("using_rstudio_product works as expected when `RSTUDIO_PRODUCT` is set", { # nolint: line_length_linter
withr::local_envvar(list("RSTUDIO_PRODUCT" = "CONNECT"))
expect_true(using_rstudio_product())
expect_true(using_rstudio_product(name = "CONNECT"))
expect_false(using_rstudio_product(name = "WORKBENCH"))
expect_true(using_posit_connect())
})