I'm encountering a strange problem that I hope someone can shed some light on. I'm encountering a difference between how code runs in the RStudio Console and how it runs if I run R inside a terminal window. I'm running Ubuntu 20.04, with R version 4.0.01 and RStudio version 1.3.959.
If I type these two commands:
I get output that consists of 10 color codes from the Viridis color palette, as would be expected.
However, if I type the same code into R running in a terminal window, the R process hangs with 100% cpu usage (according to top). The hanging problem also occurs when an RMarkdown file in RStudio is knit, which (presumably) runs its own R session separate from the RStudio console.
I've tracked the problem down further to this line in the code for the viridis command:
fn_cols <- grDevices::colorRamp(map_cols, space = "Lab", interpolate = "spline")
Invoking that function fn_cols causes the hang, and if "Lab" is changed to "rgb" the command works.
I'm not necessarily asking for a solution to the actual problem (although of course if you have one, it would be awesome), but I'm really hoping someone can give me some details as to what's different between the RStudio Console setting and the R-in-the-terminal setting that could possibly lead to this different behavior. I've tried checking out sessionInfo() and system("printenv") and have seen a few differences, but nothing I've been able to pin down as an obvious culprit.
To make matters worse, the problem didn't seem to occur on a fresh install of Ubuntu 20.04 and R and RStudio, but it does occur on my system which has been updated-in-place a few times. So I suspect some sort of weird path or library location thing, but that's the extent of my knowledge. That's why I don't necessarily expect a solution to the problem, but do hope that someone might know how those two environments interact with the system differently.
I've also encountered some tidymodels commands that crash in RStudio, but run fine in R in the terminal, but I'll save that for another day!