Crew package does not work with vscode-R
Describe the bug When using package crew in vscode-R, local workers do not start. I have not tried remote workers. crew is now the preferred method for high-performance computing for the targets package so this will affect quite a lot of people.
To Reproduce I can reliably reproduce this using a slightly modified example from crew's introduction vignette:
library(crew)
controller <- crew_controller_local(
name = "example",
workers = 2,
seconds_idle = 10
)
controller$start()
controller$push(name = "get pid", command = ps::ps_pid())
Sys.sleep(1)
controller$pop()
The last statement should return information on the spawned workers, instead it returns NULL.
Running another example from the vignette leads to nonsensical output because no workers are started:
results <- controller$map(
command = a + b + c + d,
iterate = list(
a = c(1, 3),
b = c(2, 4)
),
data = list(c = 5),
globals = list(d = 6)
)
# -1 of 2 tasks done (-50%)
This happens every time when using vscode-R, both with a radian console and a vanilla terminal, but not in radian or a vanilla terminal outside of vscode-R, and not in RStudio.
Can you fix this issue by yourself? (We appreciate the help)
No
(If applicable) Please attach setting.json
{
"security.workspace.trust.untrustedFiles": "open",
"editor.largeFileOptimizations": false,
"editor.unicodeHighlight.ambiguousCharacters": false,
"editor.unicodeHighlight.nonBasicASCII": false,
"r.plot.useHttpgd": true,
"editor.fontLigatures": true,
"editor.fontFamily": "'CaskaydiaCove Nerd Font', Menlo, Monaco, 'Courier New', monospace",
"files.autoSave": "afterDelay",
"r.rterm.option": [
"--restore",
"--save"
],
"typescript.suggest.paths": false,
"javascript.suggest.paths": false,
"workbench.startupEditor": "newUntitledFile",
"r.rterm.mac": "/usr/local/bin/R",
"editor.fontSize": 13,
"terminal.integrated.fontSize": 13,
"editor.minimap.enabled": false,
"terminal.integrated.defaultLocation": "editor",
"window.confirmBeforeClose": "keyboardOnly",
"terminal.integrated.confirmOnExit": "hasChildProcesses",
"editor.formatOnType": true,
"editor.tabSize": 2,
"editor.inlineSuggest.enabled": true,
"codeium.enableConfig": {
"*": false,
"rmd": true,
"plaintext": true
},
"diffEditor.ignoreTrimWhitespace": false,
"gitblame.statusBarMessageFormat": "${author.name} (${commit.summary, 30}, ${time.ago})",
"codeium.enableSearch": true,
"editor.acceptSuggestionOnEnter": "off",
"editor.accessibilitySupport": "off"
}
Environment (please complete the following information):
- OS: macOS 13.6.2
- VSCode Version: 1.84.2
- R Version: 4.3.2
- vscode-R version: 2.8.2
- crew version: 0.6.0
- mirai version: 0.11.0
After a lot of help from @shikokuchuo (thanks!) I figured out that the problem lies in my non-standard libPath (that I set in .Rprofile) not being propagated to child processes. If I run Sys.setenv("R_PROFILE_USER" = "~/.Rprofile") before starting worker processes (for example, in .Rprofile), everything works.
Doing this through .Renviron however does not work, because then I get this when I start an R terminal:
r$> .vsc.attach()
Error in .vsc.attach() : could not find function ".vsc.attach"
Thanks for the investigation @uhkeller. I'm trying to grock the issue -- from the sounds of it, it has something to do with our Rprofile masking? I can have a closer look in the next week or so
I wonder if this is related to #1236?
Yes looks like the same issue. A solution should solve both.