rstudio / rstudioapi

Safely access RStudio's API (when available)
http://rstudio.github.io/rstudioapi
Other
165 stars 35 forks source link

simple insertText() call no longer works #208

Closed tjmahr closed 3 years ago

tjmahr commented 3 years ago

The documentation for insertText() says:

To operate on the current selection in a document, call insertText() with only a text argument, e.g.

insertText("# Hello\n")
insertText(text = "# Hello\n")

For 0.9, the two # Hello comments are inserted into the document.

library(rstudioapi)
insertText("# Hello\n")
# Hello
insertText(text = "# Hello\n")
# Hello

For 0.12, each one gives an error:

library(rstudioapi)
insertText("# Hello\n")
#> Error in callFun("insertText", location, text, id) : 
#>   argument "text" is missing, with no default
insertText(text = "# Hello\n")
#> Error in callFun("insertText", location, text, id) : 
#>  argument "location" is missing, with no default
Version and session info ``` r rstudioapi::versionInfo()[["version"]] #> [1] ‘1.4.869’ sessioninfo::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R version 4.0.3 (2020-10-10) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz America/Chicago #> date 2020-11-11 #> #> - Packages ------------------------------------------------------------------- #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.2) #> cli 2.1.0 2020-10-12 [1] CRAN (R 4.0.2) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.2) #> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.3) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.2) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.2) #> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2) #> highr 0.8 2019-03-20 [1] CRAN (R 4.0.2) #> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.2) #> knitr 1.30 2020-09-22 [1] CRAN (R 4.0.2) #> magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.2) #> rlang 0.4.8 2020-10-08 [1] CRAN (R 4.0.3) #> rmarkdown 2.5 2020-10-21 [1] CRAN (R 4.0.2) #> rstudioapi * 0.12 2020-11-10 [1] CRAN (R 4.0.3) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.2) #> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2) #> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.2) #> xfun 0.19 2020-10-30 [1] CRAN (R 4.0.3) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0) #> #> [1] C:/Users/Tristan/Documents/R/win-library/4.0 #> [2] C:/Program Files/R/R-4.0.3/library ```
kevinushey commented 3 years ago

Do you see this in the latest preview release?

kevinushey commented 3 years ago

Scratch that, I can reproduce as well :( I'll take a look.

kevinushey commented 3 years ago

Should now be fixed in the development version of rstudioapi.

tjmahr commented 3 years ago
insertText("# Hello\n")
#> Error: 'ranges' should be a list of 4-element integer vectors
tjmahr commented 3 years ago

Also, insertText(text = "# Hello\n") doesn't error, returns NULL, but doesn't insert text.

kevinushey commented 3 years ago

Both of those calls work for me with RStudio 1.4.1013 (the current preview release).

tjmahr commented 3 years ago

Okay, both calls work for me on the new preview version with rstudioapi 0.9 (last working CRAN version) and rstudioapi 0.12.0-9000 (current repo). And it looks like my WrapRmd add-in that uses insertText() works now.