Establishing Global Settings for R in VSCode
Awesome student Kangheng Liu figured out the following, which will be helpful for students who use the dark (default!) theme for VSCode but find that their R plots show up as black labels on a black background, so that they are not readable:
The IRkernel actually calls the R default startup process. The .Rprofile works whether inside or outside of jupyter.
The problem was R’s logic in sourcing the .Rprofile
file. It won’t load libraries/packages in starting R kernel process. To pass background color as white, we need to write a hook for that. Search for hook in the link for explanations.
The coding is as below. in .Rprofile
at home folder (or project folder, will take presendence if any):
setHook(packageEvent("grDevices", "onLoad"),
function(...) grDevices::pdf.options(bg="white"))
This will pass bg="white"
to grDevices
, which is the R graphics device package.
Thank you Kangheng, on behalf of the DSAN students, for discovering this!