REditorSupport / vscode-R

R Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=REditorSupport.r
MIT License
1.08k stars 128 forks source link

grid::grid.draw() does not work in vscode-R watcher #642

Closed wdiao-zju closed 3 years ago

wdiao-zju commented 3 years ago

grid::grid.draw() does not work and base::plot() or ggplot() works in vscode-R watcher, however, grid::grid.draw() works in Rstudio. Examples of R codes as follows:

------------ R code start --------------------------- library(grid) grid.newpage() vp <- viewport(x = 0.5, y = 0.5, width = 0.5, height = 0.25, angle=45) pushViewport(vp) a <- rectGrob() grid.draw(a) ------------ R code end---------------------------

Environment:

renkun-ken commented 3 years ago

grid.draw does not call .External.graphics(...) which is hacked to trigger plot replay as png file to show in vscode.

I recommend that you use httpgd as the graphics device. As long as you have installed the package, you might want to put the following code in your ~/.Rprofile:

options(vsc.plot = FALSE)
    options(device = function(...) {
      httpgd::hgd(silent = TRUE)
      .vsc.browser(httpgd::hgd_url(), viewer = "Beside")
    })

or you could try the latest development build and enable the plot viewer implemented in #620 based on httpgd:

options(vsc.use_httpgd = TRUE)
wdiao-zju commented 3 years ago

or you could try the latest development build and enable the plot viewer implemented in #620 based on httpgd:

options(vsc.use_httpgd = TRUE)

Thanks. I use latest development build](https://github.com/Ikuyadeu/vscode-R/releases/tag/latest. It works very well. The new plot viewer is amazing.