0
0
R Programmingprogramming~5 mins

Inline R code in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is inline R code in R Markdown?
Inline R code lets you run R commands directly inside text. It shows the result right in the sentence when you knit the document.
Click to reveal answer
beginner
How do you write inline R code in R Markdown?
Use a single backtick, then r, then your R code, and close with a backtick. Like this: `r 2 + 2`.
Click to reveal answer
beginner
What will this inline R code output? `r paste('Hello', 'World')`
It will output: Hello World inside the text where the code is placed.
Click to reveal answer
intermediate
Why use inline R code instead of writing results manually?
Inline R code keeps your document up-to-date automatically. If data or calculations change, the output updates when you knit again.
Click to reveal answer
intermediate
Can inline R code include complex expressions or just simple values?
Inline R code can include any R expression, from simple numbers to complex functions, as long as it returns a value to show.
Click to reveal answer
How do you write inline R code in R Markdown?
A`r your_code`
B```r your_code ```
C<r>your_code</r>
D{{r your_code}}
What does inline R code do when you knit an R Markdown document?
ADeletes the code from the document
BShows the code but does not run it
CRuns the code but hides the result
DRuns the code and shows the result inside the text
Which of these is a valid inline R code example?
A`r mean(c(1,2,3))`
B```r mean(c(1,2,3))```
C<r>mean(c(1,2,3))</r>
D{{mean(c(1,2,3))}}
What happens if the inline R code contains an error?
AThe code is ignored and no output is shown
BThe knitting process stops with an error message
CThe code runs but shows a blank space
DThe document knits but shows the code as text
Why is inline R code useful in reports?
AIt makes the document run faster
BIt hides all code from the reader
CIt updates results automatically when data changes
DIt formats text with colors
Explain how to use inline R code in an R Markdown document and why it is helpful.
Think about how you mix code and text in one sentence.
You got /3 concepts.
    Describe a situation where inline R code would save you time compared to writing results manually.
    Imagine you have a report with numbers that change often.
    You got /3 concepts.