R Programming Language Certification Technology & Digital Applications 2 — Questions and Answers
Question 1: Which R package is specifically designed for connecting to and querying relational databases using a unified interface?
- DBI (Correct answer)
- RODBC
- RSQLite
- dbplyr
Correct answer: DBI
DBI (DataBase Interface) provides a unified interface for connecting to relational databases in R, and other packages like RSQLite and RMySQL implement the DBI specification.
Question 2: In R, which function from the `httr` package sends an HTTP GET request to a web API?
- GET() (Correct answer)
- request()
- fetch()
- http_get()
Correct answer: GET()
The `GET()` function in the httr package sends an HTTP GET request and returns a response object containing status, headers, and content.
Question 3: What does the `jsonlite::fromJSON()` function do in R?
- Parses a JSON string or file into an R object (Correct answer)
- Converts an R object to a JSON string
- Validates JSON syntax without parsing
- Downloads JSON data from a URL
Correct answer: Parses a JSON string or file into an R object
`fromJSON()` parses JSON-formatted text or files and converts them into native R objects like lists, data frames, or vectors.
Question 4: Which R package provides tools for working with date-time data, including parsing, arithmetic, and time zone handling?
- lubridate (Correct answer)
- datetime
- chronos
- timeR
Correct answer: lubridate
The lubridate package simplifies working with dates and times by providing intuitive parsing functions and consistent handling of time zones and arithmetic.
Question 5: In R Shiny, what is the role of the `renderPlot()` function?
- Creates a reactive plot output that updates when inputs change (Correct answer)
- Saves a plot to a file on disk
- Renders a static image from a URL
- Applies a color theme to existing plots
Correct answer: Creates a reactive plot output that updates when inputs change
`renderPlot()` is a reactive rendering function in Shiny that re-executes its code block and updates the displayed plot whenever reactive dependencies change.
Question 6: Which function in R is used to read data directly from a clipboard into a data frame?
- read.table(file='clipboard') (Correct answer)
- readClipboard()
- import_clipboard()
- paste_data()
Correct answer: read.table(file='clipboard')
Using `read.table(file='clipboard', header=TRUE, sep='\t')` reads tab-separated data copied to the clipboard directly into a data frame on Windows.
Question 7: What is the primary purpose of the `rvest` package in R?
- Web scraping and parsing HTML/XML content (Correct answer)
- Sending HTTP POST requests to REST APIs
- Managing browser cookies and sessions
- Generating HTML reports from R Markdown
Correct answer: Web scraping and parsing HTML/XML content
The rvest package provides tools for web scraping, allowing R users to read HTML pages and extract structured data using CSS selectors or XPath expressions.
Which R package is specifically designed for connecting to and querying relational databases using a unified interface?