MCQs on Package Development | R

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

  1. What is the main directory that contains the R functions in an R package?
    a) R/
    b) inst/
    c) man/
    d) data/
  2. In an R package, where should the documentation for each function be stored?
    a) man/
    b) R/
    c) data/
    d) tests/
  3. 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
  4. Where should sample data sets for an R package be placed?
    a) inst/
    b) man/
    c) data/
    d) tests/
  5. Which file specifies the functions that should be exported from an R package?
    a) DESCRIPTION
    b) NAMESPACE
    c) README.md
    d) tests/
  6. 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
  7. 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
  8. Where would you typically store external files like images or help files in an R package?
    a) inst/
    b) R/
    c) man/
    d) data/
  9. 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()
  10. 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

  1. Which function in R is used to generate the documentation for a function?
    a) roxygen2::roxygenize()
    b) document()
    c) create_doc()
    d) write_doc()
  2. How do you create a documentation template for a function using roxygen2?
    a) #'
    b) #
    c) @
    d) //
  3. 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
  4. 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()
  5. Where do unit tests for an R package typically go?
    a) tests/testthat/
    b) R/
    c) man/
    d) inst/
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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

  1. 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
  2. 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()
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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()
  8. Which file should include the licensing information for your R package?
    a) LICENSE
    b) DESCRIPTION
    c) NAMESPACE
    d) NEWS.md
  9. 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
  10. 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

QnoAnswer
1a) R/
2a) man/
3a) DESCRIPTION
4c) data/
5b) NAMESPACE
6a) Specifies which functions to export and import
7a) Contains metadata about the package
8a) inst/
9c) package.skeleton()
10b) data/
11a) roxygen2::roxygenize()
12a) #'
13a) To describe the function’s parameters
14a) testthat::test_that()
15a) tests/testthat/
16a) Compares two values for equality
17d) Both a and c
18a) It generates or updates the documentation for the package
19a) To describe what the function returns
20c) testthat::test_dir()
21d) All of the above
22a) devtools::check()
23c) Check for CRAN compliance with devtools::check()
24d) DESCRIPTION
25a) Edit the DESCRIPTION file
26a) 50 MB
27a) devtools::check()
28a) LICENSE
29a) It creates a compressed package file for distribution
30a) Package functionality and adherence to CRAN policies

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top