Skip to content

Commit

Permalink
use API functions if available
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Oct 16, 2024
1 parent 3bd91a6 commit 6a71e69
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions R/code.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}


Expand Down

0 comments on commit 6a71e69

Please sign in to comment.