R Programming Language Certification Technology & Digital Applications 3 — Questions and Answers
Question 1: In R, which package allows you to create interactive, browser-based visualizations using the Plotly JavaScript library?
- plotly (Correct answer)
- ggvis
- highcharter
- rbokeh
Correct answer: plotly
The plotly R package wraps the Plotly.js library, enabling creation of interactive charts that support hover tooltips, zooming, and panning in a web browser.
Question 2: What does `Sys.getenv('HOME')` return in R?
- The value of the HOME environment variable (Correct answer)
- The R installation directory
- The current working directory
- The user's R library path
Correct answer: The value of the HOME environment variable
`Sys.getenv()` retrieves the value of system environment variables; 'HOME' typically returns the path to the user's home directory.
Question 3: Which R function writes an object to a connection using the native R binary format, preserving exact object structure?
- saveRDS() (Correct answer)
- save()
- write()
- serialize()
Correct answer: saveRDS()
`saveRDS()` serializes a single R object to a file in a binary format that can be restored with `readRDS()`, preserving the object's class and attributes.
Question 4: In R Markdown, which output format produces a standalone HTML file with interactive widgets?
- html_document (Correct answer)
- flexdashboard
- ioslides_presentation
- pdf_document
Correct answer: html_document
`html_document` output in R Markdown produces a self-contained HTML file that can embed htmlwidgets and interactive elements viewable in any browser.
Question 5: What is the purpose of `tryCatch()` in R when building robust data pipelines?
- It handles errors and exceptions gracefully without stopping execution (Correct answer)
- It catches all warnings and converts them to messages
- It validates function arguments before execution
- It retries failed operations automatically
Correct answer: It handles errors and exceptions gracefully without stopping execution
`tryCatch()` allows you to intercept errors, warnings, and messages during execution and respond with custom logic instead of halting the script.
Question 6: Which R package provides functions for reading and writing Excel files (.xlsx) without requiring Excel to be installed?
- openxlsx (Correct answer)
- XLConnect
- xlsx
- readxl
Correct answer: openxlsx
The openxlsx package reads and writes Excel .xlsx files using a pure R implementation that does not depend on Java or a local Excel installation.
Question 7: In R, what does the `parallel::makeCluster()` function create?
- A cluster of worker processes for parallel computation (Correct answer)
- A database connection pool
- A distributed file system connection
- A load-balanced web server
Correct answer: A cluster of worker processes for parallel computation
`makeCluster()` initializes a set of R worker processes (locally or on remote nodes) that can execute code in parallel using the parallel package.
In R, which package allows you to create interactive, browser-based visualizations using the Plotly JavaScript library?