0
0
R Programmingprogramming~20 mins

Inline R code in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Inline R Code Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of inline R code in a string
What is the output of this R code when run?
R Programming
name <- "Alice"
result <- paste0("Hello, `r name`!")
print(result)
A"Hello, `r name`!"
B"Hello, Alice!"
CError: object 'name' not found
D"Hello, NULL!"
Attempts:
2 left
💡 Hint
Inline R code inside strings with backticks is not evaluated automatically in base R.
Predict Output
intermediate
2:00remaining
Evaluating inline R code with glue package
What is the output of this R code?
R Programming
library(glue)
name <- "Bob"
result <- glue("Hello, {name}!")
print(result)
A"Hello, {name}!"
BError: object 'name' not found
C"Hello, Bob!"
D"Hello, NULL!"
Attempts:
2 left
💡 Hint
The glue package evaluates expressions inside curly braces {}.
Predict Output
advanced
2:00remaining
Output of inline R code in R Markdown chunk
In an R Markdown document, what will this inline R code produce when rendered? `r 2 + 3 * 4`
AError: object not found
B14
C20
D2 + 3 * 4
Attempts:
2 left
💡 Hint
Inline R code in R Markdown evaluates the expression and inserts the result.
Predict Output
advanced
2:00remaining
Error from incorrect inline R code syntax
What error does this R code produce? `r if(TRUE) print("Yes") else print("No")`
ANULL
B"Yes"
C"No"
DError: unexpected 'else' in "else"
Attempts:
2 left
💡 Hint
Inline R code expects a single expression, not a full if-else statement.
🧠 Conceptual
expert
2:00remaining
How inline R code is processed in R Markdown
Which statement best describes how inline R code (e.g., `r expression`) is processed in an R Markdown document?
AThe expression inside `r` is evaluated during knitting and its result replaces the inline code in the output.
BThe inline code is treated as plain text and appears unchanged in the output document.
CThe expression is evaluated only when the document is opened in RStudio, not during knitting.
DThe inline code is executed in a separate R session after the document is rendered.
Attempts:
2 left
💡 Hint
Think about when the R Markdown document is converted to output formats.