0
0
R Programmingprogramming~20 mins

R Console and script files in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
R Console and Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of variable assignment in R Console
What will be the output in the R console after running this code?
R Programming
x <- 5
x + 3
AError: object 'x' not found
B[1] 53
C[1] 15
D[1] 8
Attempts:
2 left
💡 Hint
Remember that '<-' assigns a value to a variable and '+' adds numbers.
Predict Output
intermediate
2:00remaining
Output of sourcing an R script file
Given an R script file named 'script.R' containing: my_var <- 10 print(my_var * 2) What will be printed in the R console after running source('script.R')?
R Programming
my_var <- 10
print(my_var * 2)
AError: object 'my_var' not found
B[1] 20
C[1] 10
DNULL
Attempts:
2 left
💡 Hint
The print function outputs the value to the console.
Predict Output
advanced
2:00remaining
Output of a function defined and called in R Console
What is the output of this R code run in the console? add <- function(a, b) { return(a + b) } add(4, 7)
R Programming
add <- function(a, b) {
  return(a + b)
}
add(4, 7)
A[1] 11
BNULL
C[1] 47
DError: object 'add' not found
Attempts:
2 left
💡 Hint
Functions return the sum of their inputs here.
Predict Output
advanced
2:00remaining
Result of running incomplete R script in console
What error message will appear if you run this incomplete R script in the console? x <- c(1, 2, 3 mean(x)
R Programming
x <- c(1, 2, 3
mean(x)
AError: unexpected end of input
B[1] 2
CError: object 'x' not found
DNULL
Attempts:
2 left
💡 Hint
Check if all parentheses are closed properly.
🧠 Conceptual
expert
2:00remaining
Difference between running code in R Console vs script file
Which statement correctly describes a key difference between running code directly in the R console and running code from an R script file?
AScript files automatically print all variable values, but console does not.
BCode in the console cannot create variables, but script files can.
CCode in the console runs line-by-line immediately, while code in a script file runs only when sourced or executed.
DConsole code runs slower than script files because it is interpreted.
Attempts:
2 left
💡 Hint
Think about when code executes in each environment.