R via Docker — A fresh start
Instructions below include
- Cleanup of existing docker
- Installation of a fresh RStudio Server via
rocker/geospatial
- Ensuring the addition of needed packages
- Installation of SAGA-GIS in the new container
- Some visual tweaks
Clean-up/Clear-out Docker
On my windows machine docker ended up taking up way too much space (e.g. well over 80Gb) and was crowding my hard disk space. I have obviously assumed you know how to get docker running on windows, If you need to figure that out see Docker.com and I found this quick video on YouTube with simple and clear instructions.
To rectify this I had to reset Docker’s virtual disk as per M. Roussy.
- Open Docker GUI
- Bug tab
- Clean/Purge data (select them all)
These steps reduced the massive footprint that Docker was holding. Now I need to restore my go-to image.
RStudio Server with geospatial packages
Dockerhub is the place to find most any image that you can imagine. In my case I use Rstudio by posit with R and numerous geospatial packages for the R environment. I find this image has most of what I need:
- Download the docker image.
In this example, I did not choose the lastest. As I want install additional packages going back a version-point may be more beneficial (e.g. to reduce occurrences of packages not being available for my version of R.)$docker pull rocker/geospatial:4.1.1
- Create a new container
docker run --name rockergeo ^ ## Name the container -d ## detached mode -v windows/folder:/home/rstudio ## share a file location with docker -p 8787:8787 ## port to view Rstudio Server -e PASSWORD=somepassword ## create the password -e TZ="America/Vancouver" ## set the timezone rocker/geospatial:4.1.1 ## docker image to use
Your docker container is now running. To use it open your web-browser and navigate to: http://localhost:8787
.
Add additional packages
Most likely not every package that you ever use is available in the default image, below I install what might be missing – based on my previous use of R
.
Hopefully from another installation, or your past experience with R
you have a list of packages that you use. To generate one:
## Save current list of packages
mypackages <- as.data.frame(installed.packages()[,c(1,3:4)])
write.csv(mypackages, "somewhere/mypackages.csv")
In the new docker session.
pks <- read.csv("~/somewhere/mypackages.csv") ## list from above
## installed already
hav <- as.data.frame(installed.packages()[,c(1,3:4)])
## to be installed
intl <- setdiff(hav$Package, pks$Package)
install.packages(intl)
Rmarkdown tweaks
Some updating will be needed, especially if generating PDF or TEX based documents run:
tinytex::install_tinytex()
Also, remember that the initial pdf builds will likely take a little extra time as TinyTex
will install the needed TEX packages.
Install of SAGA-GIS
I often use a number of SAGA-GIS modules. To make these available I need to:
- From host machine open a terminal/console:
docker exec -ti rockergeo bash
- Update repositories and install SAGA ... (I should really sort out how to install the latest version of SAGA ...)
sudo apt update sudo apt install saga
Extra: Rstudio Themes
I really like Garrick Buie’s
rsthemes
devtools::install_github("gadenbuie/rsthemes") rsthemes::install_rsthemes(include_base16 = TRUE)
To make quick changes to the theme I add the following to my global profile. Note that on a fresh install this may be a blank file.
## to open the profile file usethis::edit_r_profile()
add and save the following. Then restart R (
CTRL + SHIFT + F10
)## rsthemes from https://www.garrickadenbuie.com/project/rsthemes/ if (interactive()) { rsthemes::set_theme_light("Solarized Light {rsthemes}") rsthemes::set_theme_dark("a11y-dark {rsthemes}") rsthemes::set_theme_favorite( c("Fairyfloss {rsthemes}", #"Oceanic Plus {rsthemes}", #"Nord Polar Night Aurora {rsthemes}", "a11y-dark {rsthemes}", "One Dark {rsthemes}", "Solarized Dark {rsthemes}", "base16 Unikitty Dark {rsthemes}", "base16 Apathy {rsthemes}", "base16 Flat {rsthemes}", "Solarized Light {rsthemes}", ### start light "base16 Atelier Lakeside Light {rsthemes}", "base16 Atelier Seaside Light {rsthemes}" ) ) }
Finally, As suggested on the website add a keyboard shortcut to switch themes. From the Rstudio menu:
Tools >> Modify Keyboard Shortcuts ...
. Search forNext Favourite Theme
and add a shortcut. I useCtrl + Alt + N
.