Bird
Raised Fist0
R Programmingprogramming~5 mins

R Markdown document creation in R Programming - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is an R Markdown document?
An R Markdown document is a file that combines text, code, and output in one place. It lets you write reports that include R code and its results, all in a single document.
Click to reveal answer
beginner
How do you start an R Markdown document?
You start by creating a file with the extension .Rmd. The document begins with a YAML header enclosed by --- lines that sets the title, author, and output format.
Click to reveal answer
beginner
What is the purpose of code chunks in R Markdown?
Code chunks are sections where you write R code. When you knit the document, these chunks run the code and show the results right in the document.
Click to reveal answer
beginner
How do you write a code chunk in R Markdown?
You write a code chunk by surrounding your R code with three backticks and curly braces with 'r', like this:
```{r}
# your code here
```
Click to reveal answer
beginner
What does the 'knit' button do in RStudio when working with R Markdown?
The 'knit' button runs all the R code chunks in the document and creates a finished report in the chosen format, like HTML, PDF, or Word.
Click to reveal answer
What file extension is used for R Markdown documents?
A.rmarkdown
B.R
C.Rmd
D.md
Which section in an R Markdown document sets the title and output format?
AYAML header
BCode chunk
CFooter
DScript section
How do you include R code in an R Markdown document?
AInside code chunks marked by ```{r} ... ```
BInside HTML tags
CBetween parentheses ()
DUsing special comments
What happens when you click the 'knit' button in RStudio?
AThe code is saved but not run
BThe document is processed and output is generated
CThe document is deleted
DThe document is converted to plain text
Which output formats can R Markdown produce?
AOnly HTML
BOnly Word
COnly PDF
DHTML, PDF, Word
Explain the structure of an R Markdown document and how it combines text and code.
Think about how you write a report with explanations and R code together.
You got /4 concepts.
    Describe the steps to create and produce a report from an R Markdown document in RStudio.
    Imagine you are making a report that shows your analysis and results.
    You got /5 concepts.

      Practice

      (1/5)
      1. What is the main purpose of an R Markdown document?
      easy
      A. To store data in a spreadsheet format
      B. To write only R code without any text
      C. To create interactive web applications
      D. To combine text and R code in one file for easy report generation

      Solution

      1. Step 1: Understand R Markdown's function

        R Markdown allows mixing text and R code in one document.
      2. Step 2: Identify the purpose

        This combination is mainly used to create reports easily.
      3. Final Answer:

        To combine text and R code in one file for easy report generation -> Option D
      4. Quick Check:

        R Markdown = Text + R code for reports [OK]
      Hint: Remember: R Markdown = text + code for reports [OK]
      Common Mistakes:
      • Thinking R Markdown is only for code
      • Confusing with Shiny apps
      • Assuming it's for data storage
      2. Which of the following is the correct way to start an R code chunk in an R Markdown document?
      easy
      A. <r>```
      B. ```r{
      C. ```{r}
      D. {r}```

      Solution

      1. Step 1: Recall R code chunk syntax

        R code chunks start with three backticks followed by {r} exactly.
      2. Step 2: Match the correct syntax

        ```{r} matches the correct syntax: ```{r}
      3. Final Answer:

        ```{r} -> Option C
      4. Quick Check:

        Code chunk start = ```{r} [OK]
      Hint: Code chunks start with three backticks and {r} [OK]
      Common Mistakes:
      • Placing {r} after backticks incorrectly
      • Using angle brackets instead of backticks
      • Missing curly braces
      3. Given this R Markdown snippet, what will be the output in the final document?
      ```{r}
      x <- 5
      x * 2
      ```
      medium
      A. 10
      B. x * 2
      C. 5
      D. Error: object 'x' not found

      Solution

      1. Step 1: Understand the code chunk execution

        The code assigns 5 to x, then calculates x * 2, which is 10.
      2. Step 2: Determine output shown in document

        R Markdown shows the result of the last expression, which is 10.
      3. Final Answer:

        10 -> Option A
      4. Quick Check:

        5 * 2 = 10 [OK]
      Hint: Last expression in chunk shows output [OK]
      Common Mistakes:
      • Expecting code to print the expression itself
      • Confusing variable assignment with output
      • Thinking error occurs due to chunk
      4. You wrote this R Markdown chunk but get an error when knitting:
      ```{r}
      print('Hello World'
      ```
      What is the problem?
      medium
      A. Wrong chunk start syntax
      B. Missing closing parenthesis in print function
      C. Missing quotes around Hello World
      D. Code chunk not closed with backticks

      Solution

      1. Step 1: Check the print statement syntax

        The print function is missing a closing parenthesis.
      2. Step 2: Verify chunk syntax

        The chunk start and end are correct; quotes are present.
      3. Final Answer:

        Missing closing parenthesis in print function -> Option B
      4. Quick Check:

        print('text') needs closing ) [OK]
      Hint: Count parentheses carefully in code chunks [OK]
      Common Mistakes:
      • Ignoring missing parenthesis errors
      • Thinking chunk delimiters cause error
      • Assuming quotes are missing
      5. You want to create an R Markdown document with title "My Report", author "Alex", and output as HTML. Which YAML header is correct?
      hard
      A. --- title: "My Report" author: "Alex" output: html_document ---
      B. --- title: My Report author: Alex output: pdf_document ---
      C. --- title: "My Report" author: "Alex" output: word_document ---
      D. --- title: My Report author: Alex output: html ---

      Solution

      1. Step 1: Identify correct YAML format for title, author, output

        YAML requires --- lines, key: value pairs, and output format as html_document for HTML output.
      2. Step 2: Match options with correct YAML

        --- title: "My Report" author: "Alex" output: html_document --- uses quotes for strings and output: html_document, which is correct.
      3. Final Answer:

        --- title: "My Report" author: "Alex" output: html_document --- -> Option A
      4. Quick Check:

        YAML header with html_document output [OK]
      Hint: Use output: html_document for HTML in YAML [OK]
      Common Mistakes:
      • Using pdf_document or word_document instead of html_document
      • Missing quotes causing parsing errors
      • Incorrect output format name
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard