From 6a71e697c5dc3d01384555f78e6cd87721a84e15 Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Wed, 16 Oct 2024 10:26:54 -0700 Subject: [PATCH] use API functions if available --- R/code.R | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/R/code.R b/R/code.R index ec1f7e7..8ce74fa 100644 --- a/R/code.R +++ b/R/code.R @@ -56,29 +56,40 @@ verifyAvailable <- function(version_needed = NULL) { #' based on the version of RStudio currently available. #' #' @returns A `"numeric_version"` object, giving the version of RStudio in use. -#' +#' #' @export getVersion <- function() { - verifyAvailable() - + + # use API if available + if (hasFun("getVersion")) + return(callFun("getVersion")) + + # use fallback if not base <- .BaseNamespaceEnv version <- base$.Call("rs_rstudioVersion", PACKAGE = "(embedding)") package_version(version) + } #' Report whether RStudio Desktop or RStudio Server is in use -#' +#' #' Use `getMode()` if you need to differentiate between server #' and desktop installations of RStudio. -#' +#' #' @returns "desktop" for RStudio Desktop installations, and #' "server" for RStudio Server / RStudio Workbench installations. -#' +#' #' @export getMode <- function() { - verifyAvailable() + + # use API if available + if (hasFun("getMode")) + return(callFun("getMode")) + + # use fallback if not rstudio <- as.environment("tools:rstudio") if (rstudio$.rs.isDesktop()) "desktop" else "server" + }