Usually installing packages in R is as simple as
However sometimes you will run into errors. This could be due to the fact that the package you are trying to install has what is known as a dependency. What this means is that in order for the package to properly install and run, it requires another package to already be installed.
You can think of this like trying to install an add-on for Excel like PowerQuery without having Excel installed in the first place. Clearly it would not work.
Now if you are lucky enough to know exactly what package(s) needs to be installed first, then you can simply install it and be on your way. However, most of the time we are not that lucky. And in the case of some packages, you may need to install up to a dozen packages up front to get it to work.
The easier way, just add the following syntax to your command
install.packages("package name", dependencies = TRUE)
Remember in R, Boolean (TRUE and FALSE) must be all capital letters or R will not recognize them as Boolean.
If you are using RStudio, you can install the package using the GUI
At the top, got to Tools and select Install Packages from the drop down.
Start typing the package you want in the box, it will pop up in the window
Finally, make sure install dependencies and checked and click install.