Hi everyone, this is a two minute tutorial on using knitr.
You'll need a little bit of knitr to create your R project that you will
hand in as part of the assignments.
So let's, I've got RStudio open here, hopefully you can see it.
And I'm gonna go File, so Alt+F and New File.
And then as you look, there's all these different options here.
I'm in RStudio, by the way.
And there's all these different options here.
You want to go down to R Markdown.
There we go.
And it actually populates a simple knitr document, so let me edit the title.
I just wanna say this is a test knitr document.
Okay. And then there's a bunch of text there.
And then it shows you the r command.
The r command's here.
So, what you need is, you need three little forward,
well I don't know if these are right tick marks here or right quotation marks.
You know One's slanted from the upper left to the lower right,
so the key at least on my keyboard, that's right below Escape.
And then you need, if you put an r here in this little area,
it will execute R code, and
the comma after the r will open up a bunch of options.
So there's a ton of knitr options but cache tells R whether or not to keep it.
Probably the most useful ones for me, eval= tells whether or not it should
evaluate the code, sometimes you might just wanna show code in your document.
These are all figure things.
Results=, so you can have results as marked up,
which shows syntax highlighting as is.
Hide will hide the results, and I find that most useful.
Probably the other one that's most useful for me is echo.
So you have echo is TRUE or FALSE.
Echo TRUE shows the code, and then also shows the results of the code.
Echo FALSE does not show the code.
Okay, so any rate, here's our examples.
And it gives an example of a plot too, so plot cars.
So let's save this.
I need to save it as something, so let's call it test.Rmd.
Okay, and then I go Ctrl,
well, so I need to make sure that knitr is loaded,
but actually there's a little button right here that you can just do.
I'm on this tiny computer so it's hard to see, but
you can just actually click Knit HTML right there, and there it'll knit it.
And there you can see kinda what it looks like.
And it creates an HTML document.
So if I were, for example, to do dir in R you can see
it's created this test.html document.
That's just a standard HTML document.
You could do browse.url, browseURL?
browseURL, test.html and
it'll bring up a browser window within it, okay?
So, that's knitr in a nutshell.