Skip to content

Commit

Permalink
Merge pull request #11 from briandconnelly/add_rstudio_product
Browse files Browse the repository at this point in the history
Add `using_posit_connect()` to check for Posit Connect environments
  • Loading branch information
briandconnelly authored Sep 30, 2023
2 parents 473e589 + d0327bc commit f62c70d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
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())
})

0 comments on commit f62c70d

Please sign in to comment.