0:00
So now, we're going to create your first document.
Go ahead and log into your GitHub account,
and click on your profile and Repositories.
We're going to create a new repository entitled MyFirstDocument.
And we'll put a little description in here that says,
"My First Document for Coursera."
Again, we'll leave this as a public and we're going to initialize it with a README file.
Then click Create Repository.
Once you've got the MyFirstDocument repository created,
click on the button for Clone or Download,
and the button that says Copy to clipboard.
This gives us the URL for the actual repository.
We're going to need this in RStudio in one minute.
Go ahead and open RStudio and get it running.
Click on the button for File, New Project.
When it pops up,
you have three options for creating a new project,
either in a New Directory,
an Existing Directory, or Version Control.
We're going to use Version Control.
And there's two options here.
There's one for Git and one for Subversion. We're going to be using Git.
And when we come here,
we need to put it in that repository URL.
We're simply going to paste in what we just
copied to the clipboard. It does a couple of things.
One, it puts in the full long URL.
It also auto-creates the project directory name.
It's the same name as what we call the GitHub repository, MyFirstDocument.
Make sure that you save your project as
a subdirectory in the folder that we already created for this course.
On my computer, it's under C, RepTemplates.
So, I want to make sure that I have this folder listed here for it says,
Create project as a subdirectory of.
For right now, we'll accept the rest of the defaults.
Go ahead and click Create Project.
This takes a minute and there was
a little window there that popped up for just a second where it said, Cloning.
This is similar to what we had done previously using Git.
In this case, R is doing it for us.
We now have a new project created,
and you'll notice that it cloned and downloaded the files out of the GitHub repository.
So back in our GitHub repository,
we had one README file,
and now here in R,
read under the file directory for C:/templates/MyFirstDocument,
you'll also see that README file.
There's a couple of other files created, MyFirstDocument.Rproj,
which was created by RStudio,
and a.gitignore file that was also created by the RStudio software.
These two files, for the moment,
only exist on our hard drive because we haven't synced them back up with Git.
So now that you've got your project created,
let's go ahead and create your first document.
Click on New File, R Markdown.
We're going to put in a title, My First Document.
You'll notice that there are options here for Presentation, Shiny, and Template.
We're not going to talk about Shiny in this course,
but we will later talk about both Presentations and Templates.
For now, though, we're going to create a document and we'll choose
the default format for HTML. Click OK.
It lays everything out for you with
a basic template for an R Markdown file to get you started.
You'll notice at the top, there's information on your title,
your author name, the date, and the output format.
The next section includes a little bit of R code that we'll explain later.
And the rest is basically just simple text.
The text is marked up using some different syntax.
For example, the word R Markdown is preceded by two hash marks.
This indicates it's going to be a header and it's going to be at level two.
You'll notice a little bit further down,
we've got some markings here for a URL or a web link.
The word Knit is surrounded by two asterisks that
indicates that that word is going to be bold in our final document.
There's a little bit more R code here that runs a summary on the cars dataset,
and we're also embedding a plot.
And this is a plot of the built-in pressure dataset.
And we'll understand and explain more of this in future lessons.
But for now, let's go ahead and try compiling and producing your document.
Click on the button at the top for Knit,
and click Knit to HTML.
When you do this the first time,
you're going to need to save your file, MyFirstDocument.
When we click Save,
it creates a.RMD or R Markdown file,
and it begins compiling the document.
So, down here on the bottom left,
another little window popped open or tab for R Markdown,
and you'll see that there are some processing that goes on as it goes through
it and parses each section of the text and the embedded R code.
The output file that thing gets created is MyFirstDocument.html.
Then, on the right side,
in the viewer window,
the final produced document is shown.
This is actually an HTML viewer.
We can look at it here in RStudio,
or if we go back to our local hard drive and look in
your Reproducible or RepTemplates folder for MyFirstDocument,
you'll notice we have the HTML file shown here also.
If we click on this,
it will open in whatever your default browser software is.
So, congratulations.
You've now created your first document using R Markdown and we're
now able to view it and disseminate it to anybody that has a web browser.
Let's try a couple of the other format options.
We can go back to Knit and click Knit to Word.
So, this will create a doc formatted file.
Go ahead and do that. You'll notice when I did that,
it automatically changed some of the information at the top.
It now says output Word document as default,
and in R Markdown processing window,
it also shows that the output that was created is MyFirstDocument.docx.
There was also a little output window that popped
open that has a preview of
the My First Document here and it's shown using Microsoft Word.
You also have the option to look at this using something like Google Docs.
Finally, if you've installed the software for LaTeX,
you also can run Knit to PDF.
But to do this, you do have to have LaTeX installed.
If you've done that, go ahead and click on Knit to PDF.
Again, the output options at the top change and says PDF document file default format.
And the R Markdown processing window takes a minute to run.
And again, the output that gets created is MyFirstDocument.pdf.
It also opens a default PDF viewer window here.
If you look back in your folder on your hard drive,
you'll notice that we now have,
in addition to the HTML file,
a.docx formatted file, as well as a PDF formatted file.
We can also see this here in RStudio,
if you click on the Files tab on the bottom right,
you can also see all of the list of the files that have been created.
However, if we go back and look at your GitHub account,
you'll notice you still only see your README file.
That's because we haven't synced everything up.
Let's go ahead and do that now using Git BASH.
And when it opens, you're gonna need to make sure
that you change over to the directory that we just created.
So, we've got the RepTemplates folder and inside that folder,
you now have something called MyFirstDocument.
We can run an LS command and you can
see the list of the files that are in that directory.
But let's run a git status.
When we do that,
you'll notice there's a number of files shown here that says,
"These are things that are untracked files that are present.
These are files that only exist on our local drive and we
now need to get them up to the cloud on GitHub."
So, let's go ahead and stage these files using the git add command.
We're going to commit them,
and type in a comment like,
created my first document and output formats.
Finally, we have to push these up to the cloud.
And we can do one more check using git status,
and you'll notice that it says,
"Your branch is up-to-date.
There's nothing to commit, and your working tree is clean."
Let's go back to GitHub and do a Refresh.
When you do, you'll now notice that all the files that you had
created on your local drive also exist in your GitHub account.
So, congratulations.
You've created your first reproducible document,
you've committed everything using Version Control,
and you've backed everything up to GitHub Cloud account.