Skip to content

Commit 6a71e69

Browse files
committed
use API functions if available
1 parent 3bd91a6 commit 6a71e69

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

R/code.R

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,40 @@ verifyAvailable <- function(version_needed = NULL) {
5656
#' based on the version of RStudio currently available.
5757
#'
5858
#' @returns A `"numeric_version"` object, giving the version of RStudio in use.
59-
#'
59+
#'
6060
#' @export
6161
getVersion <- function() {
62-
verifyAvailable()
63-
62+
63+
# use API if available
64+
if (hasFun("getVersion"))
65+
return(callFun("getVersion"))
66+
67+
# use fallback if not
6468
base <- .BaseNamespaceEnv
6569
version <- base$.Call("rs_rstudioVersion", PACKAGE = "(embedding)")
6670
package_version(version)
71+
6772
}
6873

6974
#' Report whether RStudio Desktop or RStudio Server is in use
70-
#'
75+
#'
7176
#' Use `getMode()` if you need to differentiate between server
7277
#' and desktop installations of RStudio.
73-
#'
78+
#'
7479
#' @returns "desktop" for RStudio Desktop installations, and
7580
#' "server" for RStudio Server / RStudio Workbench installations.
76-
#'
81+
#'
7782
#' @export
7883
getMode <- function() {
79-
verifyAvailable()
84+
85+
# use API if available
86+
if (hasFun("getMode"))
87+
return(callFun("getMode"))
88+
89+
# use fallback if not
8090
rstudio <- as.environment("tools:rstudio")
8191
if (rstudio$.rs.isDesktop()) "desktop" else "server"
92+
8293
}
8394

8495

0 commit comments

Comments
 (0)