Skip to content

R programming language

Gabor Szarnyas edited this page Oct 6, 2017 · 22 revisions

Tutorials

Visualization

Advanced topics

R readability rules (at least, one version from the Berkeley): https://docs.google.com/document/d/1esDVxyWvH8AsX-VJa-8oqWaHLs4stGlIbk8kLc5VlII/edit

Advanced R usage: http://adv-r.had.co.nz/ -- advanced topics, like exception handling, metaprogramming or profiling by Hadley Wickham

Data table cheat sheet: https://s3.amazonaws.com/assets.datacamp.com/img/blog/data+table+cheat+sheet.pdf

RStudio cheat sheet: https://www.dropbox.com/s/0moch6xocili6v9/RStudio%20Shortcuts.pdf?dl=0

How to install packages on Linux

Check out this tutortial: http://www.r-bloggers.com/installing-r-packages/

Well nothing could be easier. We just fire up an R shell and type:

> install.packages("ggplot2")

In theory the package should just install, however:

* if you are using Linux and don’t have root access, this command won’t work.
* you will be asked to select your local mirror, i.e. which server should you use to download the package.

The scripts show a "cannot open the connection" error

Quitting from lines 7-7 (plotLines.rhtml) 
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
Calls: knit ... write.csv -> eval.parent -> eval -> eval -> write.table -> file
Execution halted

The problem is that R is unable to write to some directory under the site-library dir.

sudo chown -R $USER:$USER /usr/local/lib/R/site-library/

Snippets

Use superscripts on the y axis:

ys = -10:10
yvalues = parse(text=paste("10^", ys, sep=""))

Templates

2d_3data_different_shapes

Download template.

Installing tidyverse on Ubuntu

On my Mint 18 (Ubuntu 16.04) installation, for both R 3.2.x and 3.4.y, installing tidyverse resulted in the following error:

ERROR: dependencies ‘rvest’, ‘xml2’ are not available for package ‘tidyverse’

To fix this, I had to install the libxml2-dev package:

sudo apt install -y libxml2-dev
Clone this wiki locally