0% found this document useful (0 votes)
5 views2 pages

cs446_tool-assembling-a-document-with-r-markdown

The document provides a guide on how to create and manage R Markdown files in RStudio, including steps for creating, saving, and setting the working directory. It outlines the structure of an R Markdown file, which consists of a preamble, whitespace for text, and code chunks for R code. Finally, it explains how to 'knit' the file into an HTML document and convert it to a PDF if needed.

Uploaded by

hasiba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

cs446_tool-assembling-a-document-with-r-markdown

The document provides a guide on how to create and manage R Markdown files in RStudio, including steps for creating, saving, and setting the working directory. It outlines the structure of an R Markdown file, which consists of a preamble, whitespace for text, and code chunks for R code. Finally, it explains how to 'knit' the file into an HTML document and convert it to a PDF if needed.

Uploaded by

hasiba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

TOOL

Assembling a Document With R Markdown


R Markdown files are a convenient way to view and write R code. They also let you create reproducible documents easily, so that you
can compile a report directly from the RStudio window. Use this tool to help you create, save, and use an R Markdown file, as well as
to “knit” the file to an HTML document.

Creating and Saving an R Markdown File


1. To create an R Markdown document, click File > R Markdown in the RStudio window. Leave the settings as Document and HTML,
then add a title.
2. To save your document, click File > Save, then type the title of your R Markdown file and include the extension .Rmd. Keep track
of where you save the document.
3. Sometimes you’ll write a command in your R Markdown file to access a data file located on your computer and run this command
from the R console. To make sure you correctly specify the folder location of the data file, set your R console to work from the
same directory to which you’ve saved the R Markdown file.
• Check your working directory settings by typing getwd() in the console and pressing Enter.
• If the working directory is different from where you saved the R Markdown file, set your working directory by typing setwd("")
into the console. Click between the quotation marks, press your Tab key, and then select the folder where you saved the
R Markdown file.

Summarizing and Visualizing Data


© 2021 Cornell University 1
Cornell Bowers College of Computing and Information Science
Anatomy of an R Markdown File
Once you’ve created your R Markdown document, you’ll see that it contains three main spaces: a preamble, whitespace to write plain
text, and a gray space to write code. Once you run the code, you will see it as output within the R Markdown file, in the console of your
RStudio window, or both.

Settings Run

Preamble:
• Use this space to
write file information.
Whitespace:
• Use this space to write
text descriptions.
• Create section headers
Code Chunk:
with the text: ##.
• Begin with the text ```{r},
and end with ```.
• Use this space to write code Code Output:
and comments, just like an • This can appear inline in the
R script. R Markdown window, in the
• Run code by selecting how console, or both.
much of the code you’d like • Change where you see output
to run from the Run icon. by clicking the Settings icon and
selecting Chunk Output Inline,
Chunk Output in Console, or
both.

Knitting and Exporting an R Markdown File


When you’re ready to combine the components of your R Markdown file into a single document, use the following steps:
1. Click Knit > Knit to HTML to create an HTML document from your R Markdown file.
2. If you wish to convert the HTML document to a PDF, open the HTML file in a browser window, then select File > Print >
Destination and select Save as PDF.

Summarizing and Visualizing Data


© 2021 Cornell University 2
Cornell Bowers College of Computing and Information Science

You might also like