From f2aacb21131e5f147a11aad84200048e55ed0c88 Mon Sep 17 00:00:00 2001 From: Tim Taylor Date: Thu, 17 Oct 2024 10:07:47 +0100 Subject: [PATCH 1/3] Fix #621 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. --- R/aab-rstudio-detect.R | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/R/aab-rstudio-detect.R b/R/aab-rstudio-detect.R index 3bd329bd..19a3726e 100644 --- a/R/aab-rstudio-detect.R +++ b/R/aab-rstudio-detect.R @@ -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 } From 9d722176363458fb61c27356241d13a61764f7d0 Mon Sep 17 00:00:00 2001 From: Tim Taylor Date: Thu, 17 Oct 2024 11:38:13 +0100 Subject: [PATCH 2/3] fix: erroneous version comparison - fixes a comparison between strings to a comparison between a numeric_version and a string (a valid op). - Uses getNamespaceVersion as clearer and part of base API as well as still being performant. --- R/aab-rstudio-detect.R | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/R/aab-rstudio-detect.R b/R/aab-rstudio-detect.R index 19a3726e..b844d73a 100644 --- a/R/aab-rstudio-detect.R +++ b/R/aab-rstudio-detect.R @@ -36,11 +36,7 @@ rstudio <- local({ 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" + new_api <- getNamespaceVersion(ns) >= "0.17.0" d$desktop <- if (new_api) ns$getMode() else ns$versionInfo()$mode } From dfe880bf8e6ce35179ee66252dcbbaf4f541ac7f Mon Sep 17 00:00:00 2001 From: Tim Taylor Date: Thu, 17 Oct 2024 12:01:37 +0100 Subject: [PATCH 3/3] fix: erroneous version comparison (again)! --- R/aab-rstudio-detect.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/aab-rstudio-detect.R b/R/aab-rstudio-detect.R index b844d73a..a295c846 100644 --- a/R/aab-rstudio-detect.R +++ b/R/aab-rstudio-detect.R @@ -36,7 +36,7 @@ rstudio <- local({ if (d$api) { ns <- asNamespace("rstudioapi") d$ver <- if (d$api) ns$getVersion() - new_api <- getNamespaceVersion(ns) >= "0.17.0" + new_api <- package_version(getNamespaceVersion(ns)) >= "0.17.0" d$desktop <- if (new_api) ns$getMode() else ns$versionInfo()$mode }