Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #621 #733

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are comparing version numbers as strings, you probably want package_version()? Also, getNamespaceVersion() is simpler and better IMO.

Copy link
Contributor Author

@TimTaylor TimTaylor Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes to both! Thank you. Have updated the PR (performance improvement remains the same for by use case).

FI - I cribbed that comparison from https://github.com/r-lib/rlang/blob/3d48c13d052724cd5997a730ea41bc8e6991691b/R/standalone-cli.R#L463. Is it worth flagging the string comparison issue there as well?

d$desktop <- if (new_api) ns$getMode() else ns$versionInfo()$mode
}

d
}
Expand Down
Loading