Skip to content

Quiz 3 :Developing Data Products (Data Science Specialization) Answers 2025

Question 1 – Which item is required for an R package to pass R CMD check without warnings or errors?

DESCRIPTION file
❌ vignette
❌ unit tests
❌ a demo directory
❌ example data sets

Explanation:
Every valid R package must contain a DESCRIPTION file. It provides metadata (Package name, Version, Title, Description, Author, etc.) and is essential for R CMD check to succeed. The others are optional extras.


Question 2 – Which of the following is a generic function in a fresh R installation?

predict
show
❌ colSums
❌ dgamma
mean
❌ lm

Explanation:
Generic functions use method dispatch (like UseMethod() or setGeneric()), meaning different behaviors for different object classes.

  • predict() – S3 generic

  • mean() – S3 generic

  • show() – S4 generic (from methods package, loaded by default)

  • lm() – not generic, it’s a function that creates linear models.

  • colSums() and dgamma() are simple non-generic functions.


Question 3 – What function gets the function body for an S4 method function?

getMethod()
❌ getS3method()
❌ getClass()
❌ showMethods()

Explanation:
getMethod(f, signature) retrieves the function definition for an S4 method of a given generic f.

  • getS3method() is only for S3 methods.

  • getClass() shows metadata about an S4 class, not the function.

  • showMethods() just lists available methods.


Question 4 – Correct Roxygen2 documentation for createmean() function

#' This function calculates the mean
#'
#' @param x is a numeric vector
#' @return the mean of x
#' @export
#' @examples
#' x <- 1:10
#' createmean(x)

❌ Other options use createmean(y) (wrong argument) or omit required tags.

Explanation:
To produce a valid Roxygen2 help file:

  • Must describe function.

  • Include @param, @return, @export, and @examples.

  • Example must use the correct argument (x).
    That makes this version the complete and correct documentation header.


🧾 Summary Table

Q# ✅ Correct Answer(s) Key Concept
1 DESCRIPTION file ✅ Required metadata for any R package
2 predict ✅, show ✅, mean ✅ Built-in generics in R
3 getMethod() ✅ Retrieves S4 method definitions
4 Roxygen2 block with createmean(x) Complete, valid documentation