0
0
R Programmingprogramming~20 mins

Parameterized reports in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parameterized Reports Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A[1] 1 2 3 4
B[1] 0 1 2 3 4
C[1] 1 2 3
DError: object 'params' not found
Attempts:
2 left
💡 Hint
Remember that seq_len(n) generates a sequence from 1 to n.
🧠 Conceptual
intermediate
1:30remaining
Purpose of parameters in R Markdown reports
What is the main purpose of using parameters in R Markdown reports?
ATo speed up report rendering by caching results
BTo convert R Markdown files into HTML only
CTo automatically generate plots without user input
DTo allow dynamic input values that change report output without editing code
Attempts:
2 left
💡 Hint
Think about how parameters help customize reports.
🔧 Debug
advanced
2: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)
AThe parameter 'year' is not defined before use
BThe filter condition uses the same name 'year' for column and parameter causing ambiguity
CThe subset function is misspelled
DThe data frame 'data' is empty
Attempts:
2 left
💡 Hint
Check variable names in the filter condition carefully.
📝 Syntax
advanced
2: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?
A
params:
  - threshold: 10
B
parameters:
  threshold = 10
C
params:
  threshold: 10
D
parameters:
  threshold: "10"
Attempts:
2 left
💡 Hint
YAML uses key-value pairs with colon and indentation.
🚀 Application
expert
2: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))
A3
B2
C4
D1
Attempts:
2 left
💡 Hint
Count how many scores are strictly greater than 15.