Saturday, October 22, 2016

Oh, I must go down to the R again : R cran packages emacs ESS installing libraries scripting

Debian Jessie (22nd October 2016)

The latest version of R is available via:

$ sudo apt install r-recommended 

Many R packages are also debian packages

So ggplot2 scales and dplyr can be installed like:

sudo apt install r-cran-ggplot2 r-cran-scales r-cran-dplyr

Those that are not can be installed from R itself thus:

$ R
> install.packages('mice', dep = TRUE)

Not available errors here are likely because the mirror you've chosen doesn't have the packages, the UK mirrors always seem incomplete. use CA1 in America for best results.

To load the library:


> library("ggplot2")

The best way to use R seems to be through EMACS. Install the ess package, which should recognise .R files

Type:


(ess-toggle-underscore nil) C-x C-e

In an emacs scratch window to get rid of the insanely annoying perversion of the underscore key, or put

(add-hook 'ess-mode-hook
          (lambda ()
            (ess-toggle-underscore nil)))


in .emacs

It is possible to make R scripts, but *obviously* this:

#!/usr/bin/R
cat("hello\n")



doesn't work, for reasons.

This is one way:

#!/bin/sh
R --slave --vanilla <
cat("hello\n")

EOF


But you can't write filters like this

littler works fairly well as I remember:


$ sudo apt-get install r-cran-littler

#!/usr/bin/r 
cat("hello\n")

http://dirk.eddelbuettel.com/code/littler.examples.html


and there's a newer Rscript thingy, not clear which is better

No comments:

Post a Comment