Skip to content
Brewster Malevich edited this page May 4, 2016 · 20 revisions

burnr Cookbook

The official guide to cooking with burnr.

Table of Contents

## Make a data.frame with annual columns and columns for each series

Let's say that you want to use an fhx object to create a data.frame that has one row for each year and columns for each series. This is fairly simple with the reshape2 package.

library('reshape2')

data(lgr2)

d <- dcast(lgr2$rings, 'year ~ series', value.var = 'rec_type')

This loads the reshape2 package and then loads the lgr2 fhx object from burnr, which we can use as an example dataset. The last line "casts" the ring data in lgr2 using the year column as rows, the series column as columns and then fills the body of the data.frame with values from rec_type.

Note that when you're casting the data, you may be missing several years from your rows. You can see this in our this example by running head(d) - our first year skips from 1366 to 1411:

year LGR54 LGR44 LGR47 ...
1366 inner_year NA NA ...
1411 NA inner_year NA ...
1423 unknown_fi unknown_fs NA ...
1424 recorder_year recorder_year NA ...
1425 recorder_year recorder_year NA ...
... ... ... ... ...

This is because the series have no recorded observations between 1366 and 1411. In FHX2, and FHX2 files, this is recorded as "null years" but we cut these null years out to save space and computation time. This usually doesn't affect people's code, but it's still something to be aware of.

One dirty way to get around this is

library(plyr)

year_range <- seq(min(lgr2$rings$year), max(lgr2$rings$year))
filler <- data.frame(year = year_range,
                     series = rep('hackishSolution', length(year_range)),
                     rec_type = rep(NA, length(year_range)))

d <- dcast(rbind(lgr2$rings, filler), 
           'year ~ series', value.var = 'rec_type', 
           subset = .(series != 'hackishSolution'))

which should then fill in that null space.

year LGR54 LGR44 LGR47 ...
1366 inner_year NA NA ...
1367 NA NA NA ...
1368 NA NA NA ...
1369 NA NA NA ...
1370 NA NA NA ...
... ... ... ... ...
## Simple Recipe Template _Your name ()_

Short description of what your recipe will do. Keep the language simple and approachable. Don't be pedantic.

All recipes need two parts, regardless of whether you use full section-headings or not: setup and the guts.

Setup

Describe all of the libraries you need to import, data you need to load, and functions you need to define as setup for the actual example in the recipe. Keep it short and digestible.

In general, all recipe code should be explicit rather than implicit. People should be able to reproduce your result based on what you've written in the recipe. Also, be sure your code is readable. This is paramount.

Present code blocks like this:

library('burnr')
    
thisIsAFunction()
look <- 'a_variable'

You can show inline code print('like this').

The Guts (or whatever you want to name this section)

Now that everything has been setup. This is where you present your cook trick or method. Show your code and explain what you're doing and why you're doing it. Assume that the reader has a moderate understanding of R.

Remember that readers should be able to reproduce your results!

Clone this wiki locally