Open jimgar opened 11 months ago
Hi Jim,
The init.R
error you are getting is related to the vscode-R
extension default path settings and for this open issue #10. I believe that once the .Rprofile
file will be set properly that should solve the issue. Meanwhile, could you please check if the below code solve the issue:
# Source: https://github.com/REditorSupport/vscode-R/wiki/Plot-viewer#svg-in-httpgd-webpage
if (interactive() && Sys.getenv("TERM_PROGRAM") == "vscode") {
if ("httpgd" %in% .packages(all.available = TRUE)) {
options(vsc.plot = FALSE)
options(device = function(...) {
httpgd::hgd(silent = TRUE)
.vsc.browser(httpgd::hgd_url(history = FALSE), viewer = "Beside")
})
}
}
Hi @RamiKrispin
Thanks for getting back to me.
I ran the above code chunk in the postCreateCommand radian console. Then, I ran plot.R.
I get the following error.
Error in .vsc.browser(httpgd::hgd_url(history = FALSE), viewer = "Beside") :
could not find function ".vsc.browser"
XQuartz also opened to show a couple of pages from View(diamonds)
. No plots appeared.
Could you please try the following:
Rebuild Container
optiondevcontainer.json
is set to launch a terminal with a radian instance (see Configuration
on the yellow rectangle in the below screenshot)bash
process and launch radianplot.R
code (see output on screenshot below)Please let me know what you are getting.
Yeah, that works, I see same as your screenshot and no XQuartz windows
Great! I am trying to figure out how to solve it, I hope the setting of the.Rprofile
will solve it.
@jimgar I was able to set the .Rprofile
, and it should now be stable. If you want to check, an early version is available here, I am going to add documentation and update the tutorial as well.
That's great @RamiKrispin! I don't have time for the next few days to get back into it, sorry, but please do let me know when the tutorial is all updated. I'll happily run through the whole thing at that point :)
I'm getting a similar issue. Sourcing '/root/.vscode-R/init.R' does not result in any of the .vsc.*
objects being built. Even if I start a new R session and run source('/root/.vscode-R/init.R')
, the objects do not get created. Nor does source('/root/.vscode-server/extensions/reditorsupport.r-2.8.4/R/session/init.R', chdir = TRUE)
. I have tried it in both R and radian.
Here is my .Rprofile for reference.
if (interactive() && Sys.getenv('TERM_PROGRAM') == 'vscode' && Sys.getenv('RSTUDIO') == '') {
source(file.path(Sys.getenv('HOME'), '.vscode-R', 'init.R'))
options(vsc.rstudioapi = TRUE)
if ('httpgd' %in% .packages(all.available = TRUE)) {
options(vsc.plot = FALSE)
options(device = function(...) {
httpgd::hgd(silent = TRUE)
.vsc.browser(httpgd::hgd_url(history = FALSE), viewer = 'Beside')
})
}
}
So it seems like the .Rprofile gets run before all the VS Code init files are created, so I fixed this by making sure those init files exist before running R/radian.
# devcontainer/devcontainer.json
"postStartCommand": "until [ -f /root/.vscode-R/init.R ]; do sleep 0.1; done; radian",
Also, I noticed that for the R/radian session created with the container that /root/.Rprofile
was not actually executed. There are two good ways to fix this.
${R_HOME}/etc/Rprofile.site
.Rprofile
location in an environment variable in the "containerEnv"
part of devcontainer/devcontainer.json
: "R_PROFILE_USER": "/root/.Rprofile"
Hi Rami
Thank you for this interesting tutorial.
I'm in the section Running R code and experiencing some issues.
If I open
./tests/plot.R
and run it, XQuartz opens and I get popup windows displaying the data previews and plots.I cloned the repo and worked through all the other examples up to this point just fine. With this one, I open the repo as the root folder, then build the container. Something appears to go wrong with the postCreateCommand: A terminal launches with Radian as expected, but with the following
I'm not sure why it is saying that
/root/.vscode-R/init.R
doesn't exist, because I can open a bash terminal andcat
the file contents.It also took a while to build, over 20 minutes. This seems particularly long in my experience of using Docker at work, but I don't know if it indicates some sort of problem? I guess there are just a lot of dependencies and steps involved. Rebuilding is practically instantaneous of course but rebuilding without cache resulted in another 20+ min wait.
I noticed that there are a few issues with
devcontainer.json
and wondered if they could be the cause. I believe one is just a missing comma, but it doesn't make a difference if I put it in or not. And if I follow the other recommendation and putsettings
intocustomizations
>vscode
>settings
that also does nothing.I'm at a loss for how to debug this any further.
I'm on a MacBook Pro with M1 chip, macOS Sonoma 14.0.
My VS Code "about" info:
Output from the build