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

Environment detection helpers for Workbench and Connect #290

Open
fh-mthomson opened this issue Dec 21, 2023 · 0 comments
Open

Environment detection helpers for Workbench and Connect #290

fh-mthomson opened this issue Dec 21, 2023 · 0 comments

Comments

@fh-mthomson
Copy link

I'd love generalizable versions of rstudioapi::isAvailable() that can detect in which environment code is running to then gate logic (e.g., authentication patterns that differ b/w Workbench and local), to prevent ad hoc picking of env vars (that may drift over product versions).

A starting point translated from some wrappers I've used:

# duplicative of `rstudioapi::IsAvailable()` but avoids circular logic if `rstudioapi` is not installed
get_env_rstudio_ide <- function() {
  Sys.getenv("RSTUDIO_PROGRAM_MODE")
}

is_env_rstudio_ide_desktop <- function() {
  get_env_rstudio_ide() == "desktop"
}

is_env_rstudio_ide_workbench <- function() {
  get_env_rstudio_ide() == "server"
}

is_env_rstudio_ide <- function() {
  is_env_rstudio_ide_desktop() || is_env_rstudio_ide_workbench()
}

is_env_connect <- function() {
  # have also used `USER` or `USERNAME`
  Sys.getenv("LOGNAME") == "rstudio-connect"
}

# Processes executing on a server (Workbench or Connect) ----
is_env_server <- function() {
  is_env_rstudio_ide_workbench() || is_env_connect()
}

Related to https://github.com/r-lib/httr2/pull/410/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant