Skip to content

R programming language

Gabor Szarnyas edited this page Aug 13, 2020 · 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 some packages:

sudo apt install -y libssl-dev libxml2-dev libcurl4-openssl-dev

RBGL

RBGL can be installed through Bioconductor, which currently (late 2018) requires R 3.5+.

You might also need to install the XML package separately:

install.packages('XML')

Example snippet:

library(RBGL)

con <- file(system.file("test.gxl", package="RBGL"))
coex <- fromGXL(con)
close(con)

This returns an error:

Error in xmlEventParse(contents, graph_handler(), asText = TRUE, saxVersion = 2) : 
  Can't parse 
In addition: Warning message:
In UseMethod("as.list") : closing unused connection 3 ()

The solution of to drop system.file, which loads the file from the installation directory of the package. Do not forget to adjust the working directory with setwd.

library(RBGL)

con <- file("test.gxl")
coex <- fromGXL(con)
close(con)

RStudio does not start

RStudio does not start on Xubuntu with the following error:

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.

Aborted (core dumped)

Solution (source):

sudo apt-get install libqt5gui5
Clone this wiki locally