Challenge - 5 Problems
Parameterized Reports Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of parameterized R Markdown report chunk
Consider this R Markdown chunk that uses a parameter
n to generate a sequence. What will be the output when n = 4?R Programming
params <- list(n = 4) seq_output <- seq_len(params$n) print(seq_output)
Attempts:
2 left
💡 Hint
Remember that seq_len(n) generates a sequence from 1 to n.
✗ Incorrect
The parameter n is set to 4, so seq_len(4) produces the sequence 1, 2, 3, 4. Printing it shows [1] 1 2 3 4.
🧠 Conceptual
intermediate1:30remaining
Purpose of parameters in R Markdown reports
What is the main purpose of using parameters in R Markdown reports?
Attempts:
2 left
💡 Hint
Think about how parameters help customize reports.
✗ Incorrect
Parameters let users provide inputs that change the report's content or calculations without modifying the code itself.
🔧 Debug
advanced2:30remaining
Identify the error in parameter usage
This R Markdown snippet tries to use a parameter
year to filter data but causes an error. What is the error?R Programming
params <- list(year = 2023) data <- data.frame(year = c(2022, 2023, 2024), value = c(10, 20, 30)) filtered <- subset(data, year == year) print(filtered)
Attempts:
2 left
💡 Hint
Check variable names in the filter condition carefully.
✗ Incorrect
The condition 'year == year' compares the column 'year' to itself, always TRUE. To compare to the parameter, use 'year == params$year'.
📝 Syntax
advanced2:00remaining
Correct syntax to define parameters in YAML header
Which YAML header snippet correctly defines a parameter
threshold with default value 10 for an R Markdown report?Attempts:
2 left
💡 Hint
YAML uses key-value pairs with colon and indentation.
✗ Incorrect
The correct syntax uses 'params:' followed by the parameter name and value with proper indentation and colon.
🚀 Application
expert2:30remaining
How many rows will the filtered data have?
Given this R code in a parameterized report with parameter
min_val = 15, how many rows will filtered_data contain?R Programming
params <- list(min_val = 15) data <- data.frame(id = 1:5, score = c(10, 15, 20, 25, 30)) filtered_data <- subset(data, score > params$min_val) print(nrow(filtered_data))
Attempts:
2 left
💡 Hint
Count how many scores are strictly greater than 15.
✗ Incorrect
Scores greater than 15 are 20, 25, and 30, so filtered_data has 3 rows.