19
Interacting with R making your life with R more pleasant

Sheffield_R_ July meeting - Interacting with R - IDEs, Git and workflow

Embed Size (px)

Citation preview

Interacting with Rmaking your life with R more pleasant

IDEs - huh? Why?

● IDE=integrated development environment● blurred line - many text editors have features

in this direction● syntax highlighting (at minimum)● integrated completion, help● …● Make your life easier!

IDEs/editors

● default editor/GUI● RStudio● TextMate● Sublime● emacs● vim● RCommander etc….

Emacs

● Emacs is a very powerful text editor● Serves as an IDE for any code

(e.g. C++, python, …)● Heavy on keyboard shortcuts● Ships with ESS=Emacs Speaks Statistics for

interacting with R, S and SAS, which has been in development for 20 years

Emacs

Can set up with autocomplete, and automatic help

Emacs

Easily select and execute chunks

Integrated, executable help

E.g. C-c C-r execute region; C-enter execute line; C-c C-f re/load function

Integrated, executable help

Emacs

Multisyntax highlighting (e.g. for Knitr)

Integration with git

Emacs: pros/cons

Pros● Amazingly powerful● Very efficient editing● Multi-code● Great if you already

use emacs● free/open, X-platform

Cons● Steep learning curve● You already use

another editor● RSI?!

Emacs

Some resources:

http://en.wikipedia.org/wiki/Emacshttp://ess.r-project.org/http://ess.r-project.org/refcard.pdfhttp://www.gnu.org/software/emacs/

TextMate WorkflowTextMate is a

“plain old” text editor (similar to SublimeText2) TextMate

Analysis scriptsRmd files

Shiny ui & server files

R shellsource(“file.R”)

runApp()

ShellknitRmd

make

bash

R WorkflowGenerate data

Store it

Clean it

Analyse it

Analyse it

knitr

TextMate R Features

R shellsource(“file.R”)

runApp() Can run R within TM.Templates for most things

Pros, Cons• Load up and tear down R

shells easily

• Easy to test code without polluting analysis workspace

• Can work on remote server with SSH

• Copy pasting to test code

• Time waiting for scripts to reload data (caching helps)

Tips• Script as much as possible with shell, R, perl etc.

• Makefiles make it easy to build workflows: https://github.com/mathew-hall/SheffieldR/blob/master/dplyr/Makefile

• Unix philosophy: Files/scripts/functions should do one thing and do it well

• Consider using virtual machines to package up your environment

• Emacs shortcuts work in R console (some in TextMate):• ^R back-search• ^A ^E jump to start, end of line• ^T,M-t transpose char, word• ^U,^K, ^Y,M-y kill to start,end of line, yank last killed text, cycle through killed text

R on the web - R-fiddle.org

• Don’t have access to R? Don’t panic!!!

• R-fiddle lets you use R in the cloud via your browser

• As name suggests - this is best for just fiddling….

• But you can embed the console into your own page

Click “save” to store code on their server

Use URL to retreive

Click embed to either embed just code, or code + console

Cool huh?!

Jupyter (in development)

• Building on iPython notebooks - interactive documents integrating Python code, graphics, text etc. Easy to write if you know JSON

• Although iPython can be extended to integrate R code, Jupyter extends the idea to numerous languages including R

• Still under development but R example notebook is viewable online