One way to make your analyses reproducible is to use R markdown documents.
R markdown documents are an example of a literate programming
language that can be used to interleave code, text, plots, and math,
in a way that you can distribute them easily to other people.
So I'm just going to go through this R markdown
document that's in the course R package.
So I'm going to start up here at the top.
So this YAML, or this is the front banner our markdown document.
And so you can define, for example, the title of the document,
the author of the document, and what output format you want it to be,
whether it's an HTML document or you want it to be a presentation or a PDF file.
If you look at the help files for
our markdown, you can output it in a variety of different formats.
I've actually added some extra information here that,
it needs to be there because we have an R package that this is part of.
But you don't necessarily have to do that for every R markdown document you used.
Now I'm going to skip this next section, this is all for sort of setting up
the code so that it looks right for the document to look pretty.
And I'm going to go into sort of the different components of this.
So, I'm going to start by talking about compiling documents.
So you can compile this document here by actually clicking on this knit button.
So if I click on knit, what will happen is,
our studio will run a knitter on this and will create an R markdown document.
Which then looks like this, so here, it's formatted very nicely, and
you can see it's an HTML document which I can then share with other people.
And so a couple of other things I wanted to talk about with this document.
One is, if I change the output format up here, if I go up here and I change this
to a PDF document and recompile this, then I actually get a different output.
So now I'm going to get a PDF file as an output, instead of before I had an HTML
file, so if I compile it like that, now I have this PDF that I can distribute.
You can do the same thing with Word or like I said a number
of other different output formats.
And so that is the first thing is that you can compile it to different types.
The next thing is that you can name the code chunk.
So here I have a code chunk.
Code chunk is just basically some R code that I have invented in the text, and
you can do that.
You can put a new code chunk in by doing chunks up here.
Insert chunk and it puts in like a new chunk of code right there.
I'm going to delete that so you can just see here that I have a chunk and
after the R part here I just type chunk1 and so that's the name of that chunk.
So when I compile the document, I you know click knit then what it's going to do
is a lot of text happening up here in the R mark down window.
And one of the things it does is it tells you what the chucks are called.
And so as its going through one of those chunks the labels was chuck1.
And so if you label all of your chucks then you'll be able to go through and
figure out which part of your code broke if it did.