Skip to content

Commit

Permalink
Fix #621
Browse files Browse the repository at this point in the history
This commit conditions on the presence of rstudioapi 0.17.0. If
satisfied then use the new getMode() function
(https://github.com/rstudio/rstudioapi/releases/tag/v0.17.0).
Otherwise maintain the old behaviour.

Printing of a slowish data frame in RStudio improved from ~18
seconds, to ~3 seconds with this commit and rstudioapi v0.17.0.
  • Loading branch information
TimTaylor committed Oct 17, 2024
1 parent 9fc1bbd commit f2aacb2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions R/aab-rstudio-detect.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ rstudio <- local({
args = commandArgs(),
search = search()
)
d$ver <- if (d$api) asNamespace("rstudioapi")$getVersion()
d$desktop <- if (d$api) asNamespace("rstudioapi")$versionInfo()$mode

if (d$api) {
ns <- asNamespace("rstudioapi")
d$ver <- if (d$api) ns$getVersion()

# Pull version from namespace rather than via `utils::packageVersion()`
# to avoid slowdown (see https://github.com/r-lib/rlang/pull/1657 and
# https://github.com/r-lib/rlang/issues/1422)
new_api <- ns[[".__NAMESPACE__."]][["spec"]][["version"]] >= "0.17.0"
d$desktop <- if (new_api) ns$getMode() else ns$versionInfo()$mode
}

d
}
Expand Down

0 comments on commit f2aacb2

Please sign in to comment.