I seem to be sharing a lot of code with coauthors these days. Many of them are novice/intermediate R users and don’t realize that they have to install packages they don’t already have.
Is there an elegant way to call installed.packages(), compare that to the ones I am loading and install if missing?
Yes. If you have your list of packages, compare it to the output from
installed.packages()[,"Package"]and install the missing packages. Something like this:Otherwise:
If you put your code in a package and make them dependencies, then they will automatically be installed when you install your package.