Skip to content

Fix issues in rstudioapi emulation#422

Merged
renkun-ken merged 10 commits intoREditorSupport:masterfrom
MilesMcBain:master
Oct 16, 2020
Merged

Fix issues in rstudioapi emulation#422
renkun-ken merged 10 commits intoREditorSupport:masterfrom
MilesMcBain:master

Conversation

@MilesMcBain
Copy link
Copy Markdown
Collaborator

Resolves the issues discussed in #421:

  1. If an addins.dcf file from a package is malformed it could cause an error when trying to write the JSON to drive the addin picker. This error could cause the vsc.attach function to fail to run fully. This was not very common. I found only one example in {shrcts}.

I added extra checks to look for malformed files, and to only select the first few columns, assuming those contain the information I want to display. The whole update_addins_registry call is wrapped in a try-catch so that if it throws an error it is converted to a message about the failure and the consequences. vsc.attach will complete otherwise normally.

  1. On Windows library(tidyverse) fails due to the cli package trying to interrogate the version of RStudio if it is available. I have put in implementations for getVersion and versionInfo that should allow this to work in the short term.

The plan is to discuss this with RStudio to see if we can get something less fragile.

Finally, to use the RStudio API emulation the user must set options(vsc.rstudioapi = TRUE) in the .Rprofile. I have put documentation about this in the README and will add it to the wiki.

Sorry for the hassles!

Comment thread R/rstudioapi_util.R Outdated
Comment thread R/rstudioapi_util.R Outdated
Copy link
Copy Markdown
Member

@renkun-ken renkun-ken left a comment

Choose a reason for hiding this comment

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

LGTM

@renkun-ken
Copy link
Copy Markdown
Member

@Ikuyadeu We might need a release once this PR is merged 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.

@renkun-ken
Copy link
Copy Markdown
Member

Maybe off the topic but https://github.com/Ikuyadeu/vscode-R/blob/master/src/rstudioapi.ts#L306 could be removed.

@MilesMcBain
Copy link
Copy Markdown
Collaborator Author

Still not sure if this is working properly on Windows. I just tried to install the vsix and I am getting issues. Not sure if I installed the right thing.

@MilesMcBain
Copy link
Copy Markdown
Collaborator Author

Oh yeah looks like I installed an old one. Let me confirm.

@MilesMcBain
Copy link
Copy Markdown
Collaborator Author

No. I'm seeing something very strange.

Using the vsix file built by the CI:

  • On Linux, no issues.
  • On my Windows work computer:
[ins] r$> .vsc.attach()
Error in .vsc.attach() : object 'rstudioapi_util_env' not found

Which is totally weird, since I can do:

[ins] r$> vsc_attach_env <- environment(.vsc.attach)

[ins] r$> vsc_attach_env$rstudioapi_enabled()
[1] TRUE

But if no rstudioapi stuff is in that environment, and no lockfiles etc created on in tmp folder.

It's really spinning me out.

@MilesMcBain
Copy link
Copy Markdown
Collaborator Author

OK OK OK. I got it. It was an issue with my .Rprofile which had some old stuff in there, manually sourcing init.R.

ALL GOOD. 😌

@renkun-ken
Copy link
Copy Markdown
Member

I tried the latest commit on macOS and Windows 10 VM and everything looks good so far.

@renkun-ken renkun-ken merged commit 7c20d2e into REditorSupport:master Oct 16, 2020
@almaceleste
Copy link
Copy Markdown

Error in .vsc.attach() : object 'rstudioapi_util_env' not found
I got it. It was an issue with my .Rprofile which had some old stuff in there, manually sourcing init.R.

@MilesMcBain, I have the same error message on my Ubuntu.
could you explain in more detail, how you solve this problem?

@MilesMcBain
Copy link
Copy Markdown
Collaborator Author

@almaceleste .vsc.attach() is called at the end of an init.R script that runs when an R terminal is created. I was getting this error because I had call to vsc.attatch() in my .Rprofile, which I think was a hangover from an old way that the extension used to work.

Check for any calls to this function in any of your session startup code and remove.

@almaceleste
Copy link
Copy Markdown

@MilesMcBain, I have no vsc.attach() in my .Rprofile, only this code:

source(
    file.path(
        Sys.getenv(
            if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"
        ), ".vscode-R", "init.R"
    )
)
options(vsc.rstudioapi = TRUE)

@renkun-ken
Copy link
Copy Markdown
Member

@almaceleste options(vsc.rstudioapi = TRUE) should run before source(), or otherwise it won't work.

@almaceleste
Copy link
Copy Markdown

@renkun-ken, thanx, it helps me.
now I do not get errors when running Create R terminal and Launch RStudio Addin commands, and I get RStudio Addins list successfully.
I think this should be described more obviously in the instruction and in the wiki

@renkun-ken
Copy link
Copy Markdown
Member

@almaceleste Good to know it works for you now.

I think this should be described more obviously in the instruction and in the wiki

Definitely. @MilesMcBain Would you mind updating docs so that users know how to enable it exactly? (e.g. #422 (comment) won't work)

@MilesMcBain
Copy link
Copy Markdown
Collaborator Author

I added a bit extra to the wiki: https://github.com/Ikuyadeu/vscode-R/wiki/RStudio-addin-support#enabling-rstudio-addin-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants