Jump to slides, install, settings, packages, sumatra, resources
Find info about the fall 2018 course at Potsdam university here.
Here are the slides I use for R courses in several versions:
- handout (one pdf page per slide)
- presentation (animated with LaTeX \onslide et al.)
- source code (.Rnw, I suggest rightclick - save as)
You can download all datasets or the complete repository at once.
The presentation template is available through
berryFunctions::
createPres
.
First install R itself and then Rstudio:
- R itself
- R on Windows: https://cloud.r-project.org/bin/windows/base/release.htm (update through installr)
- R on Mac: follow e.g. these instructions: https://www.r-bloggers.com/installing-r-on-os-x
- R on Linux Ubuntu: See instructions below
- Rstudio on all platforms: https://www.rstudio.com/products/rstudio/download/#Desk
Installing R on Linux Ubuntu so that sudo apt upgrade
updates to the latest R version if outdated
(idea from Kris Eberwein and Dean Attali):
Open a terminal (CTRL+ALT+T) and paste (CTRL+SHIFT+V) the following lines.
Replace xenial
with e.g. trusty
if you have another Ubuntu version (check in shell with lsb_release -a
):
18.10 cosmic-cran35, 18.04 bionic-cran35, 16.04 xenial, 14.04 trusty
sudo echo "deb https://cloud.r-project.org/bin/linux/ubuntu xenial/" | sudo tee -a /etc/apt/sources.list gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 gpg -a --export E084DAB9 | sudo apt-key add - sudo apt-get update sudo apt-get install r-base r-base-dev
In case you run into GPG problems like the example below, try replacing both gpg lines with the single line (idea source):
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E084DAB9
gpg: requesting key E084DAB9 from hkp server keyserver.ubuntu.com ?: keyserver.ubuntu.com: No route to host gpgkeys: HTTP fetch error 7: couldn't connect: No route to host gpg: no valid OpenPGP data found. gpg: Total number processed: 0 gpg: keyserver communications error: keyserver unreachable gpg: keyserver communications error: public key not found gpg: keyserver receive failed: public key not found
Suggested Rstudio settings (for reproducibility and compatibility):
- Tools - Global Options - General
- ON: Restore previously open source documents at startup
- OFF: Restore .Rdata into workspace at startup
- Save workspace to .RData on exit: NEVER
Instead usesave(object, file="object.Rdata")
after long computations.
You can load them later withload("object.Rdata")
.
- Tools - Global Options - Code - Display
- ON: Show margin (Margin column:80) People hate horizontal scrolling!
- ON: Highlight R function calls
- Tools - Global Options - Code - Saving
- Line ending conversion: Windows (CR/LF)
- Default Text Encoding: UTF-8
- Tools - Global Options - Code - Completion - Completion Delay
- Show completions after characters entered: 2
- Show completions after keyboard idle (ms): 0
- Tools - Global Options - Sweave
- Weave Rnw files using: knitr
- Tools - Modify Keyboard Shortcuts
- remove
CTRL+Y
from the command "paste last yank" (if you want it to mean "redo" as in other programs) - Set Working Directory to Current Document's Directory:
CTRL + H
- remove
Installing add-on R packages usually is easy from within R (and works without admin rights):
install.packages("ggplot2")
On Linux, some packages with external dependencies (like rJava) can be more difficult.
In such cases, you probably just want to open a terminal (CTRL+ALT+T) and paste (CTRL+SHIFT+V) sudo apt-get install r-cran-rjava
(all lower-cased).
Here's the official information on this topic.
Installing the sf
package for spatial data is a bit tricky on Linux because it needs a recent version of gdal.
If install.packages("sf")
does not work, please try the following:
sudo apt-get install libudunits2-dev
sudo add-apt-repository ppa:ubuntugis/ppa && sudo apt-get update
sudo apt-get install gdal-bin
sudo apt install libgdal-dev libproj-dev
I like to use sumatra PDF viewer as the default viewer.
It doesn't lock files from editing, hence currently opened files can be changed (by R, e.g.).
It comes in Rstudio/bin/sumatra
and I like to change some settings:
open Rstudio/bin/sumatra/sumatrapdfrestrict.ini
and set SavePreferences = 1
open and close a pdf, so that Rstudio/bin/sumatra/SumatraPDF-settings.txt
will be created
now change the following entries:
DefaultZoom = fit page
(probably already the default)ShowToc = 0
DefaultDisplayMode = single page
- R-weekly - weekly newsletter about all things R
- Rbloggers - blog aggregator about R
- Shiny - web application framework for R/Rstudio
- Rmarkdown - document/notebook generation framework for R/Rstudio
- Github guides - Introduction to github
- http://stat545.com/topics.html (excellent tutorial)
- https://www.edx.org/course/introduction-r-programming-microsoft-dat204x-0 (Datacamp, with login, but free)
- http://tryr.codeschool.com/levels/1/challenges/1 (codeschool, interactive, login to save progress)