Getting Started with R
1 Miscellaneous R tips
1.1 Installing R packages
CRAN packages
To install an R package that is available at CRAN, the default R package repository, from within R (e.g. in the R console in RStudio), use the install.packages()
function.
The install.packages()
function will handle dependencies within R — i.e., it will install other R packages that your package depends on. Occasionally, when the install function needs to compile a package from source, errors arise that relate to missing system dependencies (i.e. software outside of R).
On Mac and Linux, these system dependencies are best installed outside of R, such as with homebrew
on Mac or apt
on Ubuntu. The errror message you got when trying to install an R package should tell you which system dependencies are needed.
On Windows, you can use the installr
package to install such dependencies or other software from within R — for example:
install.packages("installr") # Install the installr package first
::install.RStudio() # Install RStudio
installlr::install.python() # Install Python installr
Installing packages from Github
To install a package from Github, use either the devtools or the remotes package – for example:
install.packages("remotes") # Install the remotes package
::install_github("kbroman/broman") # Install from a repository using "<username>/<repo-name>" remotes
This will install the package from source, so you will need to make sure you are able to do so by following the instructions in the section right above this one.