Skip to content

Environment detection helpers for Workbench and Connect #290

Open

Description

@fh-mthomson

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions