I suggest we need a canonical for this (it comes up all the time, let's merge the duplicates into it). Below are my suggestions on what are duplicates, and non-duplicates, and why; let me know what you think:
- Suggested canonical How to load packages in R automatically?. This has three good answers and is already the most upvoted.
- Duplicate: R - how to “save” the loaded packages
- The inverse of the question, which may also be a duplicate, in disguise, although this gets into locating multiple .Rprofile files Make package in R not required to load when I startup R/RStudio?
- Not exact duplicate: there are some nuances due to the way RStudio manages paths with whether/which .Rprofile is correctly picked up or not, see my answer How to load packages automatically when opening a project in RStudio
- Not a duplicate: there can be issues with loading a package which has been installed, specifically due to Windows permissions used when installing Packages won't run after installing in Rstudio. And there can be other non-platform reasons, or just install hiccups, as the OP found.
- and a near-duplicate, but just to show that the symptom keywords can be completely different: r - object not found in script, but found in console . (This was the question today which motivated me to find a canonical).