Vscode-r: Issues with rstudioapi emulation

Created on 15 Oct 2020  ·  18Comments  ·  Source: Ikuyadeu/vscode-R

A couple of things I noticed when the update landed on my work PC:

  • tidyverse calls the rstudioapi to check the version which errors, stopping it from being attached.
  • For some reason the R building of the addin list fails which interferes with .vsc.attach.

@Ikuyadeu @renkun-ken tidyverse is a bit of a showstopper. The second issue might be to do with my work PC library setup which is a bit unusual. I'll so some debugging on it now.

Is it possible to roll back to previous release?

bug

Most helpful comment

@MilesMcBain @renkun-ken Thank you for your early works. I'll put that notification on the CHANGELOG.
After Rstudio issue reports are stopped for more than 2 weeks, let's change default to be TRUE.

All 18 comments

I have the same issue. Any pointers on how to fix/downgrade?

(love the new features though! Thanks!)

Yes sorry @dcangst, you can install a vsix file from a recently tagged release. Or if you want a very recent build you might try the one here:

https://github.com/Ikuyadeu/vscode-R/actions/runs/300521275

Instructions on manual vsix install:
https://code.visualstudio.com/docs/editor/extension-gallery#:~:text=Install%20from%20a%20VSIX%23,vsix%20file.

no worries! thanks for the quick reply!!

I've figured out the second issue. This is to do with malformed addins.dcf files. In this case from shrtcts on my work machine. I can do some filtering to protect against it and perhaps put the whole parsing thing in a try-catch so that it doesn't stop the session being attached properly.

I guess we need to do a quick fix to opt-in this feature using options(vsc.rstudioapi = TRUE).

By default, it is not enabled and rstudioapi-related code will not be sourced?

@MilesMcBain @Ikuyadeu What do you think?

I think it's a good idea. :+1:

@MilesMcBain I don't quite get what's not working.

image

library(tidyverse) seems to work normally?

this is what I get when running the master branch using 'f5':
Screenshot 2020-10-15 at 13 43 51

─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.2 (2020-06-22)
 os       macOS Catalina 10.15.7      
 system   x86_64, darwin17.0          
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Europe/Zurich               
 date     2020-10-15                  

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version     date       lib source                             
 assertthat    0.2.1       2019-03-21 [1] CRAN (R 4.0.2)                     
 backports     1.1.10      2020-09-15 [1] CRAN (R 4.0.2)                     
 blob          1.2.1       2020-01-20 [1] CRAN (R 4.0.2)                     
 broom         0.7.1       2020-10-02 [1] CRAN (R 4.0.2)                     
 callr         3.5.1       2020-10-13 [1] CRAN (R 4.0.2)                     
 cellranger    1.1.0       2016-07-27 [1] CRAN (R 4.0.2)                     
 cli           2.1.0       2020-10-12 [1] CRAN (R 4.0.2)                     
 colorspace    1.4-1       2019-03-18 [1] CRAN (R 4.0.2)                     
 crayon        1.3.4       2017-09-16 [1] CRAN (R 4.0.2)                     
 DBI           1.1.0       2019-12-15 [1] CRAN (R 4.0.2)                     
 dbplyr        1.4.4       2020-05-27 [1] CRAN (R 4.0.2)                     
 desc          1.2.0       2018-05-01 [1] CRAN (R 4.0.2)                     
 devtools      2.3.2       2020-09-18 [1] CRAN (R 4.0.2)                     
 digest        0.6.25      2020-02-23 [1] CRAN (R 4.0.2)                     
 dplyr         1.0.2       2020-08-18 [1] CRAN (R 4.0.2)                     
 ellipsis      0.3.1       2020-05-15 [1] CRAN (R 4.0.2)                     
 fansi         0.4.1       2020-01-08 [1] CRAN (R 4.0.2)                     
 forcats       0.5.0       2020-03-01 [1] CRAN (R 4.0.2)                     
 fs            1.5.0       2020-07-31 [1] CRAN (R 4.0.2)                     
 generics      0.0.2       2018-11-29 [1] CRAN (R 4.0.2)                     
 ggplot2       3.3.2       2020-06-19 [1] CRAN (R 4.0.2)                     
 glue          1.4.2       2020-08-27 [1] CRAN (R 4.0.2)                     
 gtable        0.3.0       2019-03-25 [1] CRAN (R 4.0.2)                     
 haven         2.3.1       2020-06-01 [1] CRAN (R 4.0.2)                     
 hms           0.5.3       2020-01-08 [1] CRAN (R 4.0.2)                     
 httr          1.4.2       2020-07-20 [1] CRAN (R 4.0.2)                     
 jsonlite      1.7.1       2020-09-07 [1] CRAN (R 4.0.2)                     
 lifecycle     0.2.0       2020-03-06 [1] CRAN (R 4.0.2)                     
 lubridate     1.7.9       2020-06-08 [1] CRAN (R 4.0.2)                     
 magrittr      1.5         2014-11-22 [1] CRAN (R 4.0.2)                     
 memoise       1.1.0       2017-04-21 [1] CRAN (R 4.0.2)                     
 modelr        0.1.8       2020-05-19 [1] CRAN (R 4.0.2)                     
 munsell       0.5.0       2018-06-12 [1] CRAN (R 4.0.2)                     
 pillar        1.4.6       2020-07-10 [1] CRAN (R 4.0.2)                     
 pkgbuild      1.1.0       2020-07-13 [1] CRAN (R 4.0.2)                     
 pkgconfig     2.0.3       2019-09-22 [1] CRAN (R 4.0.2)                     
 pkgload       1.1.0       2020-05-29 [1] CRAN (R 4.0.2)                     
 prettyunits   1.1.1       2020-01-24 [1] CRAN (R 4.0.2)                     
 processx      3.4.4       2020-09-03 [1] CRAN (R 4.0.2)                     
 ps            1.4.0       2020-10-07 [1] CRAN (R 4.0.2)                     
 purrr         0.3.4       2020-04-17 [1] CRAN (R 4.0.2)                     
 R6            2.4.1       2019-11-12 [1] CRAN (R 4.0.2)                     
 Rcpp          1.0.5       2020-07-06 [1] CRAN (R 4.0.2)                     
 readr         1.4.0       2020-10-05 [1] CRAN (R 4.0.2)                     
 readxl        1.3.1       2019-03-13 [1] CRAN (R 4.0.2)                     
 remotes       2.2.0       2020-07-21 [1] CRAN (R 4.0.2)                     
 reprex        0.3.0       2019-05-16 [1] CRAN (R 4.0.2)                     
 rlang         0.4.8       2020-10-08 [1] CRAN (R 4.0.2)                     
 rprojroot     1.3-2       2018-01-03 [1] CRAN (R 4.0.2)                     
 rstudioapi    0.11.0-9000 2020-10-15 [1] Github (rstudio/rstudioapi@db078bb)
 rvest         0.3.6       2020-07-25 [1] CRAN (R 4.0.2)                     
 scales        1.1.1       2020-05-11 [1] CRAN (R 4.0.2)                     
 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)                     
 testthat      2.3.2       2020-03-02 [1] CRAN (R 4.0.2)                     
 tibble        3.0.4       2020-10-12 [1] CRAN (R 4.0.2)                     
 tidyr         1.1.2       2020-08-27 [1] CRAN (R 4.0.2)                     
 tidyselect    1.1.0       2020-05-11 [1] CRAN (R 4.0.2)                     
 tidyverse     1.3.0       2019-11-21 [1] CRAN (R 4.0.2)                     
 usethis       1.6.3       2020-09-17 [1] CRAN (R 4.0.2)                     
 vctrs         0.3.4       2020-08-29 [1] CRAN (R 4.0.2)                     
 withr         2.3.0       2020-09-22 [1] CRAN (R 4.0.2)                     
 xml2          1.3.2       2020-04-23 [1] CRAN (R 4.0.2)                     

[1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

(same with rstudioapi 0.11 from CRAN)

Yeah that's what I saw too.

Oh classic I see it only on my Windows work machine. Not on my personal Linux machine.

It'll be something to do with checking the terminal type for the fancy tidyverse colours I bet.

I don't think this is a solution, but defining these two rstudioapi functions 'fixes' the issue

getVersion <- function() {
    numeric_version(0)
}

versionInfo <- function() {
    numeric_version(0)
}

random version numbers work. versionInfo is supposed to return a list, still works.

I think I was on the right track:

The call which fails is in cli https://github.com/r-lib/cli/blob/cd4374c736e0c65f54ec56e40d6ba432b6c74b7b/R/rstudio-detect.R#L24

And there's a bunch of stuff in there which looks platform dependent.

I think for now the only thing that is going to work for Windows users is the fix suggested by @dcangst.

RStudio did offer to discuss any issues we had, so I might contact them and see if there's a better way to do things. Maybe we can set an env var or option that tells these tools the terminal is VSCode.

Okay PR in a few mins with fixes and option to enable the emulation.

Maybe off the topic but I notice in the wiki page that

Unlike RStudio the VSCode addin registry is regenrated every time a new R session is attached, not when a new package is installed. You can use rstudioapi::restartSession() to reattach the R session and repopulate installed addins.

It looks like user only needs to click the R: (pid) status bar item or run .vsc.attach() to re-attach the session to update the addin registry, no need to restart session?

Yeah sorry I think at one point I thought attach restarted R. I will fix.

@Ikuyadeu We might need a release for this and notice users that options(vsc.rstudioapi = TRUE) should be used to enable rstudioapi emulation in the changelog.

When the feature become more stable, then we could make it TRUE by default.

@MilesMcBain @renkun-ken Thank you for your early works. I'll put that notification on the CHANGELOG.
After Rstudio issue reports are stopped for more than 2 weeks, let's change default to be TRUE.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maxheld83 picture maxheld83  ·  4Comments

bdeshon picture bdeshon  ·  3Comments

nathaneastwood picture nathaneastwood  ·  6Comments

michaelHL picture michaelHL  ·  5Comments

Victsz picture Victsz  ·  5Comments