Top Banner
Interacting with R making your life with R more pleasant
19

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

Aug 15, 2015

Download

Software

Paul Richards
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Sheffield_R_ July meeting - Interacting with R - IDEs, Git and workflow

Interacting with Rmaking your life with R more pleasant

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

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!

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

IDEs/editors

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

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

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

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

Emacs

Can set up with autocomplete, and automatic help

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

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

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

Emacs

Multisyntax highlighting (e.g. for Knitr)

Integration with git

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

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?!

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

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/

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

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

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

bash

R WorkflowGenerate data

Store it

Clean it

Analyse it

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

Analyse it

knitr

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

TextMate R Features

R shellsource(“file.R”)

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

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

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)

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

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

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

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

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

Click “save” to store code on their server

Use URL to retreive

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

Cool huh?!

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

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

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