R MCQ
Test your R knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.
How This Practice Test Works
Every question below expands right on this page — click a question to reveal its four options, pick the one you think is correct, and you'll get instant feedback along with the correct answer and a short explanation of the reasoning. Questions are grouped by difficulty, so start with the 40 beginner questions to confirm your fundamentals, work through the 40 intermediate ones, and finish with the 20 advanced questions that mirror what exams and technical screenings actually ask. There's no sign-up, no timer, and no limit — retake the test as often as you like.
Curated by Tech Baithak Editorial Team · Last updated: June 2026
1
What is R primarily used for?
Correct Answer
Statistical computing and graphics
Explanation
R is a programming language and environment widely used for statistical computing, data analysis, and graphics.
2
Which operator is most commonly used for assignment in R?
Correct Answer
<-
Explanation
The "<-" operator is the conventional assignment operator in R, e.g. "x <- 5", though "=" also works in most contexts.
3
How do you print the value of a variable x to the console?
Correct Answer
print(x)
Explanation
print() outputs the value of an object to the console; typing just "x" at the top level also auto-prints it.
4
Which function returns the number of elements in a vector?
Correct Answer
length()
Explanation
length() returns the number of elements contained in a vector or other R object.
5
How do you create a vector containing the numbers 1, 2, and 3?
Correct Answer
c(1, 2, 3)
Explanation
c() is the combine function used to create vectors by combining individual values.
6
Which data structure in R can hold elements of different types (e.g., numbers, strings, logical values) together?
Correct Answer
list
Explanation
A list in R can hold elements of different types and structures, unlike a vector which requires all elements to be the same type.
7
What function is used to check the class/type of an object?
Correct Answer
class()
Explanation
class() returns the class attribute of an R object, such as "numeric", "character", or "data.frame".
8
How do you create a comment in R?
Correct Answer
# comment
Explanation
The "#" symbol starts a single-line comment in R; everything after it on that line is ignored by the interpreter.
9
Which function reads a CSV file into a data frame?
Correct Answer
read.csv()
Explanation
read.csv() is a base R function that reads comma-separated values files into a data frame.
10
What does NA represent in R?
Correct Answer
A missing or unavailable value
Explanation
NA is a special constant representing a missing value in R data structures.
11
Which symbol is used to access a column in a data frame by name?
Correct Answer
$
Explanation
The "$" operator accesses a named element of a list or column of a data frame, e.g. "df$column_name".
12
How do you create a sequence of numbers from 1 to 10?
Correct Answer
Both seq(1, 10) and 1:10
Explanation
Both "1:10" and "seq(1, 10)" generate the integer sequence from 1 to 10 in R.
13
What is the function to install a package in R?
Correct Answer
install.packages()
Explanation
install.packages("packagename") downloads and installs a package from a repository like CRAN.
14
Which function loads an installed package into the current session?
Correct Answer
library()
Explanation
library(packagename) attaches an already-installed package so its functions become available.
15
What is the result of TRUE + TRUE in R?
Correct Answer
2
Explanation
Logical values TRUE and FALSE are coerced to 1 and 0 respectively in arithmetic, so TRUE + TRUE equals 2.
16
Which function returns summary statistics (min, max, mean, quartiles) for a numeric vector?
Correct Answer
summary()
Explanation
summary() produces a quick statistical summary including min, max, median, mean, and quartiles for numeric data.
17
How do you create a function in R that adds two numbers?
Correct Answer
add <- function(a, b) { a + b }
Explanation
Functions in R are created using "function(args) { body }" and assigned to a name with "<-".
18
What does the "str()" function do when applied to an object?
Correct Answer
Displays the internal structure of an R object
Explanation
str() compactly displays the structure of an R object, showing types and a preview of values, useful for exploring data frames.
19
Which function checks if a value is missing (NA)?
Correct Answer
is.na()
Explanation
is.na() tests each element of an object and returns TRUE for elements that are NA.
20
How do you create a matrix with 2 rows and 3 columns from the numbers 1 through 6?
Correct Answer
matrix(1:6, nrow = 2, ncol = 3)
Explanation
matrix() accepts a vector of data along with nrow and/or ncol to define the matrix dimensions.
21
What is the result of "5 %% 2" in R?
Correct Answer
1
Explanation
The "%%" operator computes the modulo (remainder) of division; 5 divided by 2 leaves a remainder of 1.
22
Which function is used to remove an object from the current R environment?
Correct Answer
rm()
Explanation
rm() removes one or more named objects from the current environment, e.g. "rm(x)".
23
How do you select the first element of a vector named v?
Correct Answer
v[1]
Explanation
R uses 1-based indexing, so the first element of a vector is accessed with v[1], not v[0].
24
Which function converts a character string to numeric?
Correct Answer
as.numeric()
Explanation
as.numeric() coerces its argument to a numeric type, returning NA with a warning if conversion is not possible.
25
What does the "if-else" structure look like in R for checking if x is greater than 10?
Correct Answer
if (x > 10) { print("big") } else { print("small") }
Explanation
R uses C-like syntax for conditionals: "if (condition) { ... } else { ... }".
26
Which loop construct repeats a block of code for each element in a vector?
Correct Answer
for (i in vec) { ... }
Explanation
"for (variable in sequence) { body }" iterates the variable over each element of the sequence.
27
What is the default value of an uninitialized logical comparison result when comparing NA to anything, e.g. "NA == 5"?
Correct Answer
NA
Explanation
Any comparison involving NA returns NA, since the missing value's comparison result is itself unknown.
28
Which function combines two data frames by stacking their rows?
Correct Answer
rbind()
Explanation
rbind() stacks data frames or matrices vertically (row-wise), while cbind() combines them column-wise.
29
What is the correct way to get help/documentation for the function "mean" in R?
Correct Answer
help(mean) or ?mean
Explanation
Both "?mean" and "help(mean)" open the documentation page for the mean() function.
30
Which built-in constant represents an infinite value in R?
Correct Answer
Inf
Explanation
Inf represents positive infinity in R, e.g. as the result of "1/0".
31
How do you create a factor variable from a character vector?
Correct Answer
factor(x)
Explanation
factor() converts a vector into a factor, which represents categorical data with a fixed set of levels.
32
What does the function "nrow(df)" return for a data frame df?
Correct Answer
The number of rows
Explanation
nrow() returns the number of rows in a data frame or matrix; ncol() returns the number of columns.
33
Which operator is used for logical AND in R when working with single values in an if condition?
Correct Answer
&&
Explanation
"&&" performs a short-circuit logical AND on single logical values, commonly used in if() conditions, whereas "&" is vectorized.
34
Which function generates a sequence of random numbers from a normal distribution?
Correct Answer
rnorm()
Explanation
rnorm(n, mean, sd) generates n random numbers drawn from a normal distribution.
35
What is the working directory in R and which function returns it?
Correct Answer
getwd()
Explanation
getwd() returns the current working directory path; setwd() changes it.
36
How do you concatenate two strings "Hello" and "World" with a space in between?
Correct Answer
paste("Hello", "World")
Explanation
paste() concatenates strings with a space separator by default; use paste0() for no separator.
37
Which symbol is used to call a function from a specific package without loading the whole package, e.g. dplyr's filter?
Correct Answer
dplyr::filter()
Explanation
The "::" operator accesses an exported function from a specific package namespace without attaching the whole package via library().
38
What does the function "head(df)" do?
Correct Answer
Displays the first few rows (default 6) of df
Explanation
head() returns the first n rows (default 6) of a data frame or vector, useful for quickly previewing data.
39
Which assignment creates a global variable from inside a function in R?
Correct Answer
x <<- 5
Explanation
The "<<-" superassignment operator assigns a value in an enclosing (often global) environment rather than the local function scope.
40
Which RStudio/R function clears all objects from the current environment?
Correct Answer
rm(list = ls())
Explanation
"rm(list = ls())" removes all objects returned by ls() (the current environment's object names), effectively clearing the workspace.
1
What is the difference between "[" and "[[" when subsetting a list in R?
Correct Answer
"[" returns a sublist (preserving list structure), while "[[" extracts a single element directly
Explanation
Single bracket "[" subsetting returns a list containing the selected elements, while double bracket "[[" extracts the actual element itself.
2
What does the apply family function "sapply()" do?
Correct Answer
Applies a function over a list/vector and simplifies the result to a vector or matrix when possible
Explanation
sapply() is a user-friendly version of lapply() that attempts to simplify the output to a vector, matrix, or array when the results allow.
3
In the magrittr/dplyr pipe "%>%", what does "df %>% filter(x > 1) %>% select(y)" mean?
Correct Answer
The result of df is passed as the first argument to filter(), then that result is passed to select(), chaining operations left to right
Explanation
The pipe operator passes the left-hand side as the first argument of the right-hand function, enabling readable left-to-right chains of data transformations.
4
What does "lapply(x, f)" return?
Correct Answer
A list, where each element is the result of applying f to the corresponding element of x
Explanation
lapply() always returns a list of the same length as x, with each element being f applied to the corresponding element of x.
5
What is the purpose of the "dplyr::mutate()" function?
Correct Answer
To add new columns or modify existing columns based on computations from existing columns
Explanation
mutate() creates new variables or transforms existing variables within a data frame while preserving existing columns.
6
What does the "%in%" operator do?
Correct Answer
Checks whether each element of a vector is contained in another vector, returning a logical vector
Explanation
"%in%" tests membership: "x %in% y" returns a logical vector indicating whether each element of x is found in y.
7
How are environments different from lists in R?
Correct Answer
Environments have reference semantics (mutable in place) while lists are copied on modification (copy-on-modify semantics)
Explanation
Environments are mutable and passed by reference, so modifying them inside a function affects the original; lists follow R's usual copy-on-modify value semantics.
8
What does "factor(x, levels = c("low", "medium", "high"), ordered = TRUE)" create?
Correct Answer
An ordered factor where "low" < "medium" < "high" for comparison purposes
Explanation
Setting ordered = TRUE with specified levels creates an ordered factor, enabling meaningful "<" and ">" comparisons between levels based on their order.
9
What is "vectorization" in R and why is it preferred over explicit loops?
Correct Answer
Vectorized operations apply functions to entire vectors at once using optimized C code internally, generally being faster and more concise than explicit for loops
Explanation
R's vectorized functions operate element-wise on whole vectors using efficient compiled code, avoiding the overhead of interpreted loop iteration.
10
What does "tapply(data, group, function)" do?
Correct Answer
Applies a function to data, split into groups defined by "group", returning a result for each group
Explanation
tapply() splits a vector into groups according to a factor and applies a function to each group, returning an array of results.
11
What is the difference between "==" and "identical()" when comparing two R objects?
Correct Answer
"==" performs element-wise comparison (and may return NA or a vector), while identical() returns a single TRUE/FALSE checking if the objects are exactly the same in type, attributes, and values
Explanation
identical() performs a strict, whole-object comparison returning a single logical, while "==" is vectorized and can yield NA for missing values or vectors of comparisons.
12
What does the "...": (ellipsis/dots) argument allow in a function definition like "function(x, ...)"?
Correct Answer
It allows the function to accept any number of additional named or unnamed arguments, often passed along to other functions
Explanation
The "..." argument captures any number of extra arguments, which can be forwarded to other functions called within the function body.
13
What does "na.rm = TRUE" do when passed to functions like mean() or sum()?
Correct Answer
It excludes NA values from the calculation, so they do not cause the result to be NA
Explanation
Without na.rm = TRUE, the presence of any NA in the input causes functions like sum() or mean() to return NA; setting it to TRUE ignores NAs during computation.
14
What is the purpose of "set.seed(n)" in R?
Correct Answer
To initialize the random number generator so that random results are reproducible
Explanation
set.seed() fixes the state of R's pseudo-random number generator so that code involving randomness produces the same results each run.
15
What does "do.call(func, args_list)" do?
Correct Answer
Calls func with the arguments contained in args_list (a list), constructing the call dynamically
Explanation
do.call() constructs and executes a function call from a function and a list of arguments, useful for dynamic function calls.
16
What is the difference between a "data.frame" and a "tibble" (from the tibble/dplyr package)?
Correct Answer
Tibbles are a modern reimagining of data frames with stricter printing, no automatic partial matching of names, and consistent subsetting behavior
Explanation
Tibbles extend data frames with more predictable behaviors: they print more concisely, never use row names, and subsetting with "[" always returns a tibble.
17
What does "Reduce(function(a, b) a + b, c(1,2,3,4))" compute?
Correct Answer
The cumulative sum applied successively, resulting in 10
Explanation
Reduce() successively applies a binary function to combine elements of a vector into a single value; here it sums 1+2+3+4 = 10.
18
What is "lazy evaluation" of function arguments in R?
Correct Answer
Function arguments are not evaluated until they are actually used inside the function body
Explanation
R uses lazy evaluation: argument expressions are only evaluated when first accessed within the function, which can affect default arguments referencing other arguments.
19
What does the function "merge(df1, df2, by = "id")" do?
Correct Answer
Joins df1 and df2 based on matching values in the "id" column, similar to a SQL join
Explanation
merge() performs a database-style join of two data frames based on common columns or specified keys.
20
What is the difference between "&" and "&&" in R?
Correct Answer
"&" performs element-wise vectorized AND on vectors, while "&&" evaluates only the first elements and short-circuits, intended for single logical values
Explanation
"&" is vectorized over all elements, while "&&" (and "||") evaluate left to right and stop as soon as the result is determined, working on single values.
21
What does "table(x)" return for a categorical vector x?
Correct Answer
A frequency table (counts) of each unique value in x
Explanation
table() builds a contingency table of counts for each unique value (or combination of values) in the input vector(s).
22
What does "regmatches(x, regexpr(pattern, x))" accomplish?
Correct Answer
Extracts the substrings of x that match the regular expression pattern
Explanation
regexpr() finds the position of the first regex match, and regmatches() extracts the actual matched substring(s) from x using those positions.
23
What is the purpose of S3 classes in R, e.g. defining a "print.myclass" method?
Correct Answer
S3 is a simple object-oriented system based on generic functions, where methods are dispatched based on the class attribute of an object
Explanation
S3 is R's informal OOP system: a generic function like print() dispatches to a class-specific method (e.g. print.myclass) based on the object's class attribute.
24
What does "stringr::str_detect(x, pattern)" return?
Correct Answer
A logical vector indicating whether each element of x contains the pattern
Explanation
str_detect() returns TRUE or FALSE for each element of x depending on whether the pattern is found, similar to grepl() in base R.
25
What is the purpose of "group_by()" combined with "summarise()" in dplyr?
Correct Answer
To partition data into groups by one or more variables and then compute aggregate statistics per group
Explanation
group_by() splits a data frame into groups based on column values, and summarise() then computes one or more summary statistics for each group.
26
What does "match.arg()" do inside a function definition?
Correct Answer
Validates and matches a character argument against a set of allowed values, often used for default option arguments
Explanation
match.arg() is commonly used with arguments like "type = c('a', 'b', 'c')" to validate that the supplied value is one of the allowed choices and supply a default.
27
What is the effect of "drop = FALSE" when subsetting a data frame, e.g. "df[, "col", drop = FALSE]"?
Correct Answer
It keeps the result as a data frame (with one column) instead of simplifying it to a vector
Explanation
By default, selecting a single column from a data frame with "[" simplifies the result to a vector; drop = FALSE preserves the data frame structure.
28
What does the "switch()" function do in R?
Correct Answer
Selects one of several alternatives based on the value of an expression, similar to a switch/case statement
Explanation
switch(expr, case1 = result1, case2 = result2, ...) evaluates expr and returns the result corresponding to the matching case.
29
What is the purpose of the "apply(m, 1, sum)" call on a matrix m?
Correct Answer
Computes the sum of each row of the matrix, returning a vector of row sums
Explanation
apply(X, MARGIN, FUN) applies FUN over rows when MARGIN = 1, and over columns when MARGIN = 2.
30
What does "Sys.time()" return?
Correct Answer
The current date and time according to the system clock
Explanation
Sys.time() returns the current system date and time as a POSIXct object.
31
What is the difference between "deep copy" semantics and reference semantics as they apply to standard R vectors and lists?
Correct Answer
R uses copy-on-modify: assigning a vector/list to a new variable initially shares memory, but modifying either copy triggers an independent copy, so changes do not affect the original
Explanation
R's copy-on-modify semantics mean two variables can initially point to the same data, but as soon as one is modified, R makes a copy so the other remains unchanged.
32
What does "Vectorize()" do to a non-vectorized function?
Correct Answer
Creates a wrapper that allows the function to accept vector arguments by internally applying mapply()
Explanation
Vectorize() wraps a scalar function so it can be called with vector arguments, internally using mapply to apply it element-wise.
33
What does "complete.cases(df)" return?
Correct Answer
A logical vector indicating which rows of df have no missing values (NA) in any column
Explanation
complete.cases() returns TRUE for rows that contain no NA values across all (or specified) columns, useful for filtering complete observations.
34
What is the purpose of "on.exit()" inside a function?
Correct Answer
To register an expression to be executed when the function exits, regardless of how it exits (normally or via error)
Explanation
on.exit() schedules code (such as cleanup actions) to run when the enclosing function returns, whether normally or due to an error.
35
What does "is.function(x)" check?
Correct Answer
Whether x is a function object
Explanation
is.function() returns TRUE if its argument is a function, which is useful since functions are first-class objects in R.
36
What does "names(df) <- c("a", "b", "c")" do for a data frame df with three columns?
Correct Answer
Renames the existing columns of df to a, b, and c in order
Explanation
Assigning to names(df) replaces the column names of the data frame with the provided vector, in positional order.
37
What does the operator "%>%" require to be available in base R (prior to R 4.1)?
Correct Answer
A package such as magrittr (often loaded via dplyr or the tidyverse) since it is not part of base R before 4.1
Explanation
The "%>%" pipe operator originates from the magrittr package; base R introduced its own native pipe "|>" starting in version 4.1.
38
What does "as.Date("2024-01-15")" return?
Correct Answer
A Date object representing January 15, 2024, allowing date arithmetic and formatting
Explanation
as.Date() parses a string into R's Date class, enabling operations like subtraction between dates and formatted output via format().
39
What is the purpose of "pivot_longer()" and "pivot_wider()" from the tidyr package?
Correct Answer
They reshape data between "long" and "wide" formats, e.g. converting multiple columns into key-value pairs or vice versa
Explanation
pivot_longer() gathers columns into rows (wide-to-long), while pivot_wider() spreads rows into columns (long-to-wide), useful for reshaping data for analysis or plotting.
40
What does "ggplot(data, aes(x = a, y = b)) + geom_point()" produce?
Correct Answer
A scatter plot with column a on the x-axis and column b on the y-axis
Explanation
ggplot2 builds plots in layers: aes() maps data columns to visual properties (axes), and geom_point() adds a layer of points, creating a scatter plot.
1
What is the key difference between R's S4 class system and the S3 system?
Correct Answer
S4 provides formal class definitions with validity checking and multiple dispatch, defined via setClass() and setGeneric(), unlike S3's informal attribute-based dispatch
Explanation
S4 is a more rigorous OOP system with formally declared classes, slots with types, validity methods, and support for multiple dispatch, contrasting with S3's convention-based approach.
2
What does "environment(f) <- new_env" change about a function f?
Correct Answer
It changes the enclosing environment of f, affecting how f resolves free variables (lexical scoping)
Explanation
A function's environment determines where it looks up variables not defined locally or passed as arguments; reassigning it changes this lexical scope.
3
What is "non-standard evaluation" (NSE) and how does it relate to functions like "subset()" or dplyr verbs?
Correct Answer
NSE allows a function to capture the unevaluated expression of an argument (via substitute()/quote() or tidy evaluation) so it can be evaluated in a custom context, e.g. allowing column names to be referenced without quotes
Explanation
Functions using NSE (like subset() with base R, or dplyr verbs with tidy evaluation) capture argument expressions unevaluated, allowing data frame column names to be used directly as if they were variables.
4
What does "memoise" (memoization) do, and how would it typically be implemented for an R function?
Correct Answer
It wraps a function to cache results for given inputs, so repeated calls with the same arguments return cached results instead of recomputing
Explanation
Memoization caches the results of expensive function calls keyed by their arguments, often implemented using a closure over an environment that stores past results.
5
What is the purpose of "Rcpp" in the R ecosystem?
Correct Answer
A package that provides a seamless interface for integrating C++ code into R, allowing performance-critical code to be written in C++
Explanation
Rcpp simplifies calling C++ functions from R and passing data between the two languages, often used to speed up computationally intensive operations.
6
What does "force()" do when used inside a closure-generating function, e.g. in a loop creating multiple functions?
Correct Answer
It forces immediate evaluation of a lazily-evaluated argument/variable, preventing bugs where closures capture a variable's final value instead of its value at creation time
Explanation
force(x) simply evaluates x, which is used to "lock in" the current value of a variable used in a closure due to R's lazy evaluation, avoiding common loop-variable-capture bugs.
7
What is the difference between "quote()" and "eval()" in metaprogramming with R?
Correct Answer
quote() captures an expression without evaluating it (returning an unevaluated call/expression object), and eval() evaluates such an expression in a given environment
Explanation
quote() returns the unevaluated expression as a language object, which can later be passed to eval() to execute it in a specified environment.
8
What does R's "promise" object represent in the context of lazy evaluation?
Correct Answer
An internal object that stores an unevaluated expression along with its environment, evaluated only when the corresponding argument is first accessed
Explanation
Function arguments in R are represented internally as "promises" — pairs of an expression and environment — that are evaluated on first access, implementing lazy evaluation.
9
What is the difference between "tryCatch()" and "try()" for error handling?
Correct Answer
try() simply suppresses the error and returns an object of class "try-error", while tryCatch() allows specifying distinct handler functions for different condition classes (error, warning, etc.)
Explanation
tryCatch() provides structured handling with separate handlers for different condition classes (error, warning, message, etc.), while try() is a simpler wrapper that just catches errors and continues.
10
What does the "data.table" package's syntax "DT[, newcol := value]" do compared to base R or dplyr equivalents?
Correct Answer
It modifies DT in place (by reference) to add or update "newcol", avoiding the overhead of copying the entire table
Explanation
The ":=" operator in data.table performs in-place modification by reference, which is significantly more memory- and time-efficient for large datasets compared to copy-on-modify approaches.
11
What is the purpose of "match.call()" inside a function?
Correct Answer
It returns the call to the current function with all arguments matched to their formal parameter names, useful for introspection and error messages
Explanation
match.call() returns the function call as it was made, with arguments matched and named according to the function's formal arguments, often used for logging or constructing informative messages.
12
How does R's garbage collector generally decide when to free memory used by an object?
Correct Answer
R uses automatic garbage collection that reclaims memory for objects no longer referenced by any reachable variable or environment
Explanation
R automatically performs garbage collection, reclaiming memory occupied by objects that are no longer reachable, though gc() can be called manually to request collection.
13
What is a key consideration when using "parallel::mclapply()" versus "lapply()"?
Correct Answer
mclapply() distributes the computation across multiple processes/cores (using forking on Unix-like systems), which can speed up CPU-bound tasks but has overhead and platform limitations (e.g. limited support on Windows)
Explanation
mclapply() parallelizes apply-style operations via forking, beneficial for CPU-intensive tasks on multi-core Unix-like systems, but fork-based parallelism is not well supported on Windows and has process-spawning overhead.
14
What does "sys.call()" versus "sys.function()" return when called inside a function?
Correct Answer
sys.call() returns the unevaluated call that invoked the current function, while sys.function() returns the actual function object/definition being executed
Explanation
sys.call() gives the call expression (function name and arguments as written), whereas sys.function() gives the function definition itself, useful for introspection in advanced metaprogramming.
15
In R6 or Reference Classes (R5), what makes objects behave differently from standard S3/S4 objects with respect to method calls modifying state?
Correct Answer
R6/Reference Class objects have reference (mutable) semantics, so calling a method that modifies a field changes the object in place without needing reassignment
Explanation
Unlike most R objects which use copy-on-modify semantics, R6 and Reference Class (R5) objects are mutable and modified in place by their methods, similar to objects in languages like Python or Java.
16
What is the difference between "missing(x)" and "is.null(x)" when checking function arguments?
Correct Answer
missing(x) checks whether the argument x was supplied in the function call at all, while is.null(x) checks whether the value of x (which must be evaluable) is NULL
Explanation
missing() detects whether an argument was omitted from the call (without evaluating it), whereas is.null() requires evaluating the argument and checks if its resulting value is NULL.
17
How does R handle "active bindings" in an environment or R6 class?
Correct Answer
Active bindings are special variables that, when accessed or assigned, call a function instead of simply storing/retrieving a value, enabling computed properties
Explanation
Active bindings (via makeActiveBinding() or R6's "active" list) define accessor functions that run on every read/write, enabling computed or validated properties.
18
What does the "bquote()" function do, and how does it differ from "quote()"?
Correct Answer
bquote() quotes an expression but allows parts wrapped in .() to be evaluated and substituted in immediately, enabling partial substitution
Explanation
bquote() is like quote() but supports "unquoting" via .(...) syntax, allowing selected sub-expressions to be evaluated and spliced into the otherwise-unevaluated expression.
19
What is the significance of the "ALTREP" (Alternative Representation) framework introduced in R 3.5?
Correct Answer
It allows R objects like sequences (e.g. 1:1e9) to be represented compactly without materializing the full vector in memory, improving memory efficiency and performance
Explanation
ALTREP lets certain vectors (like integer sequences from ":" or memory-mapped data) be stored in compact alternative representations rather than fully expanded arrays, saving memory and time.
20
What is the practical implication of R functions being "first-class objects" with respect to passing functions as arguments, e.g. "Map(function(x, y) x + y, list1, list2)"?
Correct Answer
Functions can be assigned to variables, stored in lists, passed as arguments, and returned from other functions, enabling functional programming patterns like Map, Filter, and Reduce
Explanation
Because functions are first-class values in R, they can be manipulated like any other object — stored, passed around, and returned — which underlies higher-order functions such as Map(), Filter(), and Reduce().