Skip to content

[BUG] Addin to put selected text between ns() doesn't work #1190

Closed
@howardbaik

Description

@howardbaik

Describe the bug

I tried to insert ns() using the RStudio Addin and got this message: Your version of RStudio does not support modifyRange. This message is ultimately caused by hasFun <- rstudioapi::hasFun(fun) returning FALSE.

To Reproduce
Steps to reproduce the behavior:

  1. Write a string of text that you want to put inside ns(). (i.e. "test-ns")
  2. Inside RStudio, click Addins -> Put selected text into between ns()

Expected behavior

I'm expecting the addin to put ns() around my text (i.e. ns("test-ns"))

Screenshots

Image

session info

─ Session info ───────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.4.3 (2025-02-28 ucrt)
 os       Windows 11 x64 (build 26100)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       America/New_York
 date     2025-04-01
 rstudio  2024.12.1+563 Kousa Dogwood (desktop)
 pandoc   NA
 quarto   ERROR: Unknown command "TMPDIR=C:/Users/hbaik/AppData/Local/Temp/Rtmp46KzaM/file59cc64be47a0". Did you mean command "install"? @ C:\\PROGRA~1\\RStudio\\RESOUR~1\\app\\bin\\quarto\\bin\\quarto.exe

─ Packages ───────────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 attempt       0.3.1   2020-05-03 [1] CRAN (R 4.4.3)
 cachem        1.1.0   2024-05-16 [1] CRAN (R 4.4.3)
 cli           3.6.4   2025-02-13 [1] CRAN (R 4.4.3)
 config        0.3.2   2023-08-30 [1] CRAN (R 4.4.3)
 devtools      2.4.5   2022-10-11 [1] CRAN (R 4.4.3)
 digest        0.6.37  2024-08-19 [1] CRAN (R 4.4.3)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.4.3)
 fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.4.3)
 fs            1.6.5   2024-10-30 [1] CRAN (R 4.4.3)
 glue          1.8.0   2024-09-30 [1] CRAN (R 4.4.3)
 golem         0.5.1   2024-08-27 [1] CRAN (R 4.4.3)
 htmltools     0.5.8.1 2024-04-04 [1] CRAN (R 4.4.3)
 htmlwidgets   1.6.4   2023-12-06 [1] CRAN (R 4.4.3)
 httpuv        1.6.15  2024-03-26 [1] CRAN (R 4.4.3)
 later         1.4.1   2024-11-27 [1] CRAN (R 4.4.3)
 lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.4.3)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.4.3)
 memoise       2.0.1   2021-11-26 [1] CRAN (R 4.4.3)
 mime          0.13    2025-03-17 [1] CRAN (R 4.4.3)
 miniUI        0.1.1.1 2018-05-18 [1] CRAN (R 4.4.3)
 pkgbuild      1.4.7   2025-03-24 [1] CRAN (R 4.4.3)
 pkgload       1.4.0   2024-06-28 [1] CRAN (R 4.4.3)
 profvis       0.4.0   2024-09-20 [1] CRAN (R 4.4.3)
 promises      1.3.2   2024-11-28 [1] CRAN (R 4.4.3)
 purrr         1.0.4   2025-02-05 [1] CRAN (R 4.4.3)
 R6            2.6.1   2025-02-15 [1] CRAN (R 4.4.3)
 Rcpp          1.0.14  2025-01-12 [1] CRAN (R 4.4.3)
 remotes       2.5.0   2024-03-17 [1] CRAN (R 4.4.3)
 rlang         1.1.5   2025-01-17 [1] CRAN (R 4.4.3)
 rstudioapi    0.17.1  2024-10-22 [1] CRAN (R 4.4.3)
 sessioninfo   1.2.3   2025-02-05 [1] CRAN (R 4.4.3)
 shiny         1.10.0  2024-12-14 [1] CRAN (R 4.4.3)
 urlchecker    1.0.1   2021-11-30 [1] CRAN (R 4.4.3)
 usethis       3.1.0   2024-11-26 [1] CRAN (R 4.4.3)
 vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.4.3)
 xtable        1.8-4   2019-04-21 [1] CRAN (R 4.4.3)
 yaml          2.3.10  2024-07-26 [1] CRAN (R 4.4.3)

 [1] C:/Users/hbaik/AppData/Local/R/win-library/4.4
 [2] C:/Program Files/R/R-4.4.3/library

──────────────────────────────────────────────────────────────────────────────────────
Warning message:
In system2("quarto", "-V", stdout = TRUE, env = paste0("TMPDIR=",  :
  running command '"quarto" TMPDIR=C:/Users/hbaik/AppData/Local/Temp/Rtmp46KzaM/file59cc64be47a0 -V' had status 1

Additional context

Two things:

  1. I am hoping this bug gets fixed and I can assign a keyboard shortcut to this RStudio Addin.
  2. I investigated why rstudioapi::hasFun("modifyRange") returned FALSE in hasFun("modifyRange") returns FALSE rstudio/rstudioapi#317, and discovered that it was an RStudio bug. From conversation with @kevinushey, we should use this function instead of hasFun():
is_modifyRange_available <- function() {
  if (!rstudioapi::isAvailable()) return(FALSE)

  version_info <- rstudioapi::versionInfo()
  required_version <- package_version("XXX")  # XXX = next release of RStudio

  return(!is.null(version_info$version) &&
         version_info$version >= required_version)
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions