Transcript
Page 1: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…and learned to love SweaveHow I stopped worrying about figure placement

David LovellBioinformatics FOAM | Melbourne | 14 February 2014

CSIRO COMPUTATIONAL INFORMATICS

Page 2: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

It's doingthe working

and the thinkingthat wears

a fellow out

Page 3: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

I have an ideaI want to explore it I explore my idea by writing a computer program

I write R codeI want to ensure my exploration is reproducible and comprehensible– I explore this idea using literate programming

I use Sweave to write both R code and commentary

I want to communicate my explorations I communicate my explorations by writing a journal article

I write the article according to the journal’s instructions for authorsI want to ensure others can reproduce and comprehend my explorations– I include the literate program as Supplementary Information– I use the Supplementary Information figures in the journal article

More thinking… less working…How to use Sweave to streamline data analysis and publication

How I learned to love Sweave| David Lovell | Page 3

Page 4: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

More thinking… less working…Workflow

How I learned to love Sweave| David Lovell | Page 4

Idea

Supplementary Information

.Rnw

Figure 1.pdf

Supplementary Information

.aux

Supplementary Information

.pdf

JournalArticle

.tex

JournalArticle

.pdf

Page 5: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Let’s walk through the key steps

Page 6: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Let’s start a new project in RStudio

Page 7: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Let’s start a new project in RStudio

Page 8: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Let’s start a new project in RStudio

Page 9: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Let’s start a new project in RStudio

Page 10: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Let’s start a new project in RStudio

Page 11: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Let’s start a new project in RStudio

Page 12: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Let’s start a new project in RStudio

Page 13: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Be sure to set the project

options…

Page 14: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

… so as to use knitr to weave .Rnw

files

Page 15: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

You could also set

knitr in the global options

Page 16: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

You could also set

knitr in the global options

Page 17: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Uncheck this option

to keep .aux files

Page 18: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Now open a new Sweave (.Rnw) file…

Page 19: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Now open a new Sweave (.Rnw) file…

Page 20: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…for Supplement

ary Information

Page 21: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

This gives you a

skeleton LaTeX file…

Page 22: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…add content …compile to

PDF…

Page 23: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…here’s the compilation

report…

Page 24: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…and here’s the resulting

PDF

Page 25: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Now add code to

execute on compilation

Page 26: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

See the result?

Page 27: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Now add a “chunk” of

code…

Page 28: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…here’s the pretty-printed result

Page 29: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Here’s a “chunk” that runs silently

Page 30: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…here’s the silent result

Page 31: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Now here’s a plot that

prints immediately

Page 32: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

See the result? Code

first, plot after

Page 33: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Here’s a plot in a

“floating” figure

Page 34: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

The figure floats to the top of the

page

Page 35: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Look at the files created

on compilation

Page 36: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

The .aux file holds labels

for cross-reference

Page 37: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Compilation also creates

figures…

Page 38: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…figures named after the chunks

Page 39: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Now let’s write that Nature paper…

Page 40: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…let’s call it JournalArticl

e

Page 41: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Now we play by Nature’s

format rules

Page 42: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…still, we can cross-reference

Suppl. Info.

Page 43: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…here’s a cross-

reference

Page 44: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

…and figures

made in the Suppl. Info

Page 45: How I stopped worrying about figure placement and learned to love Sweave - David Lovell
Page 46: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

More thinking… less working…Workflow

How I learned to love Sweave| David Lovell | Page 46

Idea

Supplementary Information

.Rnw

Figure 1.pdf

Supplementary Information

.aux

Supplementary Information

.pdf

JournalArticle

.tex

JournalArticle

.pdf

Page 47: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

More thinking… less working…Workflow: write these

How I learned to love Sweave| David Lovell | Page 47

Supplementary Information

.Rnw

JournalArticle

.tex

Page 48: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

More thinking… less working…Workflow: submit these

How I learned to love Sweave| David Lovell | Page 48

Supplementary Information

.Rnw

Supplementary Information

.pdf

JournalArticle

.tex

JournalArticle

.pdf

Page 49: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

It's doingthe working

and the thinkingthat wears

a fellow out

Page 50: How I stopped worrying about figure placement and learned to love Sweave - David Lovell

Thank youCSIRO Transformational BiologyDavid LovellBioinformatics and Analytics Leader t +61 2 6216 7042e [email protected] www.csiro.au/people/David.Lovell

CSIRO MATHEMATICS, INFORMATICS AND STATISTICS


Top Related