Learn the essentials of R package development, including how to structure a package, write effective documentation, create unit tests, and publish packages on CRAN for sharing with the R community.
MCQs on Package Development in R
1. Structure of an R Package
What is the main directory that contains the R functions in an R package? a) R/ b) inst/ c) man/ d) data/
In an R package, where should the documentation for each function be stored? a) man/ b) R/ c) data/ d) tests/
Which of the following files is essential in an R package to describe the package’s metadata? a) DESCRIPTION b) NAMESPACE c) README.md d) LICENSE
Where should sample data sets for an R package be placed? a) inst/ b) man/ c) data/ d) tests/
Which file specifies the functions that should be exported from an R package? a) DESCRIPTION b) NAMESPACE c) README.md d) tests/
What does the NAMESPACE file control in an R package? a) Specifies which functions to export and import b) Contains metadata about the package c) Stores documentation d) Includes test cases
What is the function of the DESCRIPTION file in an R package? a) Contains metadata about the package b) Contains the functions of the package c) Stores test cases for the package d) Stores data used in the package
Where would you typically store external files like images or help files in an R package? a) inst/ b) R/ c) man/ d) data/
Which function is used to create a new R package structure in RStudio? a) create_package() b) new_package() c) package.skeleton() d) build_package()
What directory is typically used to store raw data files in an R package? a) inst/ b) data/ c) man/ d) tests/
2. Writing Documentation and Unit Tests
Which function in R is used to generate the documentation for a function? a) roxygen2::roxygenize() b) document() c) create_doc() d) write_doc()
How do you create a documentation template for a function using roxygen2? a) #' b) # c) @ d) //
In R, what is the purpose of the @param tag in documentation? a) To describe the function’s parameters b) To define the return type c) To specify the function’s dependencies d) To specify the function’s output format
Which function is used to create unit tests for functions in an R package? a) testthat::test_that() b) unit_test() c) check_package() d) test_package()
Where do unit tests for an R package typically go? a) tests/testthat/ b) R/ c) man/ d) inst/
What does the expect_equal() function in testthat do? a) Compares two values for equality b) Tests if a value is NULL c) Checks if a value is numeric d) Asserts that a value is true
How do you include external dependencies in your R package documentation? a) Use @import in the roxygen documentation b) Add them to the NAMESPACE file c) Include them in DESCRIPTION under Imports d) Both a and c
What does the devtools::document() function do in an R package? a) It generates or updates the documentation for the package b) It tests the package for errors c) It installs the package locally d) It packages the R package into a tarball
What is the purpose of using @return in R documentation? a) To describe what the function returns b) To document the function parameters c) To define the function’s exceptions d) To import external libraries
Which function is used to run unit tests in R? a) test_file() b) run_tests() c) testthat::test_dir() d) test_that()
3. Publishing Packages on CRAN
Which of the following is required before submitting an R package to CRAN? a) It must pass all tests b) It must have a valid DESCRIPTION file c) It must be free of errors and warnings d) All of the above
Which function in devtools is used to check an R package for CRAN submission? a) devtools::check() b) check_package() c) cran_check() d) validate_package()
What is the first step in publishing an R package on CRAN? a) Create a package using devtools b) Submit the package via the CRAN submission page c) Check for CRAN compliance with devtools::check() d) Write the package documentation
Which file must be included in the root directory of the R package to comply with CRAN submission guidelines? a) LICENSE b) README.md c) NEWS.md d) DESCRIPTION
How do you increment the version number of an R package for CRAN submission? a) Edit the DESCRIPTION file b) Use devtools::version_up() c) Use package.skeleton() d) Add a Version tag to NAMESPACE
What is the maximum size of an R package source file for CRAN submission? a) 50 MB b) 100 MB c) 200 MB d) 10 MB
How can you check if your R package passes CRAN checks before submission? a) devtools::check() b) cran_check() c) devtools::build() d) check_package()
Which file should include the licensing information for your R package? a) LICENSE b) DESCRIPTION c) NAMESPACE d) NEWS.md
What does devtools::build() do in R package development? a) It creates a compressed package file for distribution b) It publishes the package to CRAN c) It checks if the package passes all tests d) It generates the documentation
What is the key factor that CRAN reviewers primarily check in an R package before accepting it? a) Package functionality and adherence to CRAN policies b) Documentation completeness c) Package size d) Number of contributors
Answers
Qno
Answer
1
a) R/
2
a) man/
3
a) DESCRIPTION
4
c) data/
5
b) NAMESPACE
6
a) Specifies which functions to export and import
7
a) Contains metadata about the package
8
a) inst/
9
c) package.skeleton()
10
b) data/
11
a) roxygen2::roxygenize()
12
a) #'
13
a) To describe the function’s parameters
14
a) testthat::test_that()
15
a) tests/testthat/
16
a) Compares two values for equality
17
d) Both a and c
18
a) It generates or updates the documentation for the package
19
a) To describe what the function returns
20
c) testthat::test_dir()
21
d) All of the above
22
a) devtools::check()
23
c) Check for CRAN compliance with devtools::check()
24
d) DESCRIPTION
25
a) Edit the DESCRIPTION file
26
a) 50 MB
27
a) devtools::check()
28
a) LICENSE
29
a) It creates a compressed package file for distribution
30
a) Package functionality and adherence to CRAN policies