Would you mind sharing exactly what the R packages you were having problems with were?
I wonder if you were relying on globally installed versions of things instead of an R installation that had the packages wrapped into its environment. I’m more familiar with Nix, but you’ll typically see people do something like add this to a local project build input or development shell:
r-lang.withPackages with rPackages; [ r-ggplot2 r-data-table ];
Rather than nix-env -iA r-4.2 r-ggplot2 r-data-table
Or the Guix equivalent guix install r …
Globally installing things can lead to situations where you think it should work but if you really think about how the store dependencies work, they don’t.