Installing R & RStudio Libraries - Troubleshooting
Installing Libraries in R can be problematic sometimes. Here are a few hints and tips that might be useful for you.
Install sf
R uses libraries to add features and different tools, such as GIS and spatial analysis. We need to install some libraries we will be using. Follow these instructions to install the sf
library. Note the terms library and package are interchangeable.
- Open RStudio.
- In the Console type in
install.packages("sf")
and press enter.
This is (approximately) the output you should get (click the link for the full image):
Then load the library by running
library(sf)
.Check the output you get - red text does not always mean an error!
The first time you load
sf
you will probably get this message:
- This is fine. If you get some other text, it may also be fine. Read the text and see what it says. Do ask if you have questions.
Install tmap
- Repeat the process for the
tmap
package. - In the Console type in
install.packages("tmap")
.
This is (approximately) the output you should get (I’ve not included the full version because it is so long!):
- The load the library by running
library(tmap)
.
- This is fine. If you get some text, it may also be fine. Read the text and see what it says. Do ask if you have questions.
Problems
If you don’t get this output, there may have been a problem. Best move is to try loading the libraries again.
- In the Console type in
library(sf)
. - and then type in
library(tmap)
.
You should get something like this:
If you don’t, then there are a few steps you can try:
R might say a dependent library is unavailable.
- Check what the red text says. If it says (for example)
There has been an error installing the Rcpp library
, try installing that library: install.packages("Rcpp")
- Then try loading it:
library(Rcpp)
- If that works, try installing either
sf
ortmap
again.
- Check what the red text says. If it says (for example)
R might ask if you want to compile the package from source:
- Usually the best choice here is to say no, which means R will use a very slightly older version of the library, but it should be fine for our work.
- If you say yes, R will ask you to install RTools, which will probably work, but adds to the length of the setup time!
R might give you instructions to install another piece of software - try this if you can.
If none of those work, you can try uninstalling and reinstalling the library
- Remove using
remove.packages("classInt")
(e.g. for theclassInt
package) or - Open the Packages tab (on the right) and click the
X
by whichever package you want to remove:
- Remove using
If that doesn’t work, do reach out to me before the course and ask for help.
An alternative is to use RStudio.cloud / Posit.cloud.
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/deed.en. The latest version of this is available from https://nickbearman.github.io/installing-software/r-rstudio.