Before we get started with this video, we need to do one more quick software installation. What we need to do is install LaTex on your computer, and this is going to enable you to compile your R Markdown reports into PDF files. If you already have LaTex installed on your computer and you know you do, that's great. But if you don't know or you're not sure, just run these two lines of R code in RStudio and the correct files will download and install. And it will all take place in RStudio. You should be aware that this might take a few minutes, so be patient, there's a lot of files to download. But once this is finished, just come back to this video and we'll get started with making an R Markdown report. In this video we're going to go through the process of how do you create a report using R Markdown. A R Markdown document is a file that contains text, like what you might find in a word processing document. But it also incorporates R code and visualizations. And so it's a great way to do reproducible data science. Because you can hand somebody an R Markdown file, and they can, from scratch, replicate whatever kind of analysis or visualizations that you're doing. This .RMD file is in contrast to just a .R file, which is just a file of executable R commands. This is kind of harder to explain than to just show you. So let's get started by making a document and this will become more concrete. To start with you click the icon, the leftmost icon in the menu bar in RStudio. And you'll see a bunch of different kinds of files that you can create with R. And we're going to start with R Markdown file here. At this point, it's possible that you will see a pop up window that's going to ask you whether or not you want to install packages. And if this kind of thing happens, you can click Yes, just go through the process. And download all the different files that you might need to start with an R Markdown document. But eventually, you're going to get to this window that will say New R Markdown. And it will give you several choices for what kind of documents you want to create. We're going to select Document and PDF for right now. Although you could also choose an HTML file, or possibly a Microsoft Word file. After you click OK here, you see that the RStudio window changes. And there's this editing window that pops up with a console. And this is not a .R file, this is a .RMD file. The first part of the document here includes the title information for your report and the type of output that you're creating. And again, the common formats here would be an HTML document, a Word document, or a PDF document. The next lines here set up some commands for the document which you can just ignore for right now. It's just some file setup information. And then here below that, you'll see the plain text. Which when we actually compile the report and put it together in a few minutes, it's going to look like word processor output. The two pound signs here are not comments, like they are in a .R file. Instead, this is directions for how to format the text that follows it. And the two pound signs indicate that the text is going to be a bold header. And the asterisks indicate that the text will be bold in the paragraph here. Next up, you see this chunk of R code and the chunk is set off by lines that start with three apostrophes. And then there's a set of brackets in this first section here that enclose the letter r and a title for the code chunk. This title's not going to appear in the document itself, but it's a reference for you as you code. And then within this line chunk here, you see an R command. And it's a summary command for a data set that's built into R that will produce summaries of the object. You can actually run that R code within RStudio to see what kind of output it's going to generate once you compile the document. And you just double click cars, select that text and run the line as we've done before. This is just a table with two columns, speed and distance, and a set of cars. After that code chunk, there is more text that will look like we're processing output. And then we have more R code that tells R to plot the pressure object. And pressure is just a still piece of data built into R that will generate an example plot. Note here that there's this bit of text following the comma in the title for the code chunk. And what echo=FALSE here means, is it's telling RStudio to hide the raw code in the final document. So you won't actually see the code that's executed, you'll only see the output for it. So now that we understand the sort of architecture or the structure of this Markdown file, let's go ahead and compile it and see what it looks like in final form. First you want to save the R Markdown file somewhere on your computer. And once you've saved it somewhere, go ahead and click Knit in RStudio, click that button. The computer is probably going to open up this new file automatically. And if it doesn't, you can navigate to the folder where you saved your R Markdown file and you'll be able to open it up on your computer itself. This is an R Markdown report created in RStudio that includes embedded R code and commands. It's got word processor like output, R code and R output that either as what would show up in the console or in the plot preview window. As you can tell, this is really cool, because you can distribute these widely. Anybody who has R and the right data files can run them and they can see exactly what you're doing. This is really critical for transparent reproducible data science.