0
0
R Programmingprogramming~20 mins

Why advanced features enable complex work in R Programming - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Advanced R Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of nested function calls with advanced features
What is the output of this R code using advanced features like closures and environments?
R Programming
make_counter <- function() {
  count <- 0
  function() {
    count <<- count + 1
    count
  }
}
counter <- make_counter()
c(counter(), counter(), counter())
AError: object 'count' not found
B[1] 0 1 2
C[1] 1 2 3
D[1] 1 1 1
Attempts:
2 left
💡 Hint
Think about how the inner function changes the variable 'count' in its environment.
Predict Output
intermediate
1:30remaining
Output of vectorized operations with recycling
What is the output of this R code that uses vector recycling in arithmetic?
R Programming
x <- c(1, 2, 3, 4)
y <- c(10, 20)
x + y
A[1] 11 22 13 24
B[1] 11 22 33 44
C[1] 11 12 13 14
DError: non-conformable arrays
Attempts:
2 left
💡 Hint
Remember how R recycles shorter vectors to match the length of longer ones.
🔧 Debug
advanced
1:30remaining
Identify the error in advanced list manipulation
What error does this R code produce when trying to access a nested list element?
R Programming
my_list <- list(a = list(b = 1:3))
my_list$a$b[4]
AError: object 'b' not found
BError: subscript out of bounds
CNULL
DNA (no error, returns NA because index 4 is out of bounds)
Attempts:
2 left
💡 Hint
Check what happens when you access an index beyond the vector length in R.
🧠 Conceptual
advanced
1:30remaining
Why use environments for complex R programming?
Which statement best explains why environments enable complex work in R?
AEnvironments allow storing variables with different scopes, enabling modular and stateful programming.
BEnvironments automatically speed up all R code without programmer effort.
CEnvironments are only used for graphical output in R.
DEnvironments prevent any variable from being changed once created.
Attempts:
2 left
💡 Hint
Think about how environments manage variable visibility and lifetime.
Predict Output
expert
2:30remaining
Output of advanced metaprogramming with substitute and eval
What is the output of this R code using substitute and eval for metaprogramming?
R Programming
x <- 10
expr <- substitute(x + y)
y <- 5
eval(expr)
A[1] 10 + y
B[1] 15
CError: object 'y' not found
D[1] 5
Attempts:
2 left
💡 Hint
Consider when substitute captures the expression and when eval evaluates it.