R Programming Language Certification Technology & Digital Applications 5 — Questions and Answers
Question 1: In R, what is the `reticulate` package used for?
- Running Python code and sharing objects between R and Python (Correct answer)
- Interfacing R with C++ for performance
- Connecting R to cloud computing platforms
- Embedding R inside Python scripts
Correct answer: Running Python code and sharing objects between R and Python
The reticulate package provides a comprehensive interface between R and Python, allowing R users to call Python functions, import modules, and share data between sessions.
Question 2: Which R function is used to apply a function over the rows or columns of a matrix, specified by the MARGIN argument?
- apply() (Correct answer)
- sapply()
- tapply()
- mapply()
Correct answer: apply()
`apply()` iterates over rows (MARGIN=1) or columns (MARGIN=2) of a matrix or array and applies a specified function, returning a vector or matrix of results.
Question 3: What is the purpose of `withr::with_dir()` in R testing and scripting contexts?
- Temporarily changes the working directory for the duration of a code block (Correct answer)
- Creates a new directory with specified permissions
- Monitors directory changes in real time
- Sets the default directory for file output
Correct answer: Temporarily changes the working directory for the duration of a code block
`withr::with_dir()` temporarily changes the working directory for the duration of the expression and restores the original directory when done, even if an error occurs.
Question 4: In R, which package provides the `datatable()` function to render interactive, searchable HTML tables in R Markdown or Shiny?
- DT (Correct answer)
- formattable
- kableExtra
- reactable
Correct answer: DT
The DT package wraps the JavaScript DataTables library, providing `datatable()` to create interactive HTML tables with sorting, filtering, and pagination.
Question 5: Which R function retrieves the current system time as a POSIXct object?
- Sys.time() (Correct answer)
- proc.time()
- system.time()
- date()
Correct answer: Sys.time()
`Sys.time()` returns the current date and time as a POSIXct object, suitable for time-stamping operations or calculating elapsed time.
Question 6: What does `memoise::memoise()` do when wrapped around an R function?
- Caches function results so repeated calls with the same inputs return the stored result instantly (Correct answer)
- Monitors memory usage of the wrapped function
- Converts the function to use lazy evaluation
- Optimizes the function's bytecode at runtime
Correct answer: Caches function results so repeated calls with the same inputs return the stored result instantly
Memoization caches the return value of a function for each unique set of arguments; subsequent calls with the same inputs skip re-execution and return the cached result.
Question 7: In R, which package enables sending emails programmatically, supporting SMTP authentication and HTML content?
- blastula (Correct answer)
- sendmailR
- mailR
- emayili
Correct answer: blastula
The blastula package provides a modern, tidyverse-friendly interface for composing and sending HTML emails via SMTP, with support for embedded images and attachments.
In R, what is the `reticulate` package used for?