Challenge - 5 Problems
Inline R Code Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
Inline R code inside strings with backticks is not evaluated automatically in base R.
✗ Incorrect
In base R, backticks with `r` inside strings are not evaluated. The string remains as is.
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
The glue package evaluates expressions inside curly braces {}.
✗ Incorrect
The glue function evaluates {name} and replaces it with the value of the variable name.
❓ Predict Output
advanced2: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`
Attempts:
2 left
💡 Hint
Inline R code in R Markdown evaluates the expression and inserts the result.
✗ Incorrect
The expression 2 + 3 * 4 evaluates as 2 + 12 = 14.
❓ Predict Output
advanced2:00remaining
Error from incorrect inline R code syntax
What error does this R code produce?
`r if(TRUE) print("Yes") else print("No")`
Attempts:
2 left
💡 Hint
Inline R code expects a single expression, not a full if-else statement.
✗ Incorrect
The inline code syntax does not allow multi-line or compound statements like if-else without braces.
🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
Think about when the R Markdown document is converted to output formats.
✗ Incorrect
During knitting, R Markdown evaluates inline R code and inserts the results into the output document.