Skip to content

System Information#

R Versions Available to Posit Connect#

This recipe compares your local R version against the R installations available on your Posit Connect server. It uses the GET /v1/server_settings/r endpoint to obtain the R installations available to Posit Connect.

Tip

Use the Content Runtimes recipe to enumerate the R and Python versions used by content deployed to your Posit Connect server.

Workflow#

  1. Obtain the Posit Connect server URL and API Key from environment variables.
  2. Obtain your local R version using R.version.
  3. Retrieve the R installation info with the GET /v1/server_settings/r endpoint.
  4. Parse the response using httr::content.
  5. Check the response for the local R version. If it is not listed, the Posit Connect server does not contain the local R version.

Here is an example of the workflow:

library(httr)

# The connectServer URL must have a trailing slash.
connectServer <- Sys.getenv("CONNECT_SERVER")
connectAPIKey <- Sys.getenv("CONNECT_API_KEY")

myRVersion <- paste(R.version$major, R.version$minor, sep = ".")
resp <- GET(
  paste0(connectServer, "__api__/v1/server_settings/r"),
  add_headers(Authorization = paste("Key", connectAPIKey))
)
payload <- content(resp, as = "parsed", simplifyVector = TRUE)
if (myRVersion %in% payload$installations$version) {
  print("The local R version was found on the Posit Connect server")
} else {
  print(paste("Cannot find R version", myRVersion,"on the Posit Connect server"))
}

R Versions Available on Content Execution Images#

Note

This section describes a feature that is currently in beta. If you are not sure if this applies to you, please speak with your administrator.

If your Posit Connect installation uses off-host content execution with Kubernetes, Connect will be configured with one or more images which may include different versions of R.

This recipe compares your local R version against the R installations available on your Posit Connect server's configured images. It uses the GET /v1/server_settings/r endpoint to obtain the R installations available to Posit Connect, and find which images they are available on. You can use the same pattern to search for python or quarto installations.

Workflow#

  1. Obtain the Posit Connect server URL and API Key from environment variables.
  2. Obtain your local R version using R.version.
  3. Retrieve the R installation info with the GET /v1/server_settings/r endpoint.
  4. Parse the response using httr::content.
  5. Check the response for the local R version. If it is not listed, the Posit Connect server's images do not contain the local R version.

Here is an example of the workflow:

library(httr)

# The connectServer URL must have a trailing slash.
connectServer <- Sys.getenv("CONNECT_SERVER")
connectAPIKey <- Sys.getenv("CONNECT_API_KEY")

myRVersion <- paste(R.version$major, R.version$minor, sep = ".")
resp <- GET(
  paste0(connectServer, "__api__/v1/server_settings/r"),
  add_headers(Authorization = paste("Key", connectAPIKey))
)
payload <- content(resp, as = "parsed", simplifyVector = TRUE)
installations <- payload$installations
matching <- installations[ installations$version == myRVersion, ]
if (nrow(matching) > 0) {
  print("The local R version was found in the following images:")
  for (image_name in matching$image_name) {
    print(image_name)
  }
} else {
  print(paste("Cannot find R version", myRVersion,"in any available images"))
}