Week 6 · Advanced Statistical Programming using R
What is the difference between git fetch and git pull?
fetch only downloads remote commits; pull downloads and merges themfetch is for branches; pull is for filesfetch requires admin permissions; pull does notAnswer: 1) pull = fetch + merge. Use fetch if you want to inspect remote commits before integrating them.
Two students edit report.qmd at the same time and get a merge conflict. Which strategy reduces this?
main faster than the other student{{< include _eda.qmd >}} in report.qmd so each student owns a separate filegit push --forceAnswer: 2) Splitting into includes lets each person own a file. report.qmd only changes when structure changes.
Which file holds your package’s name, version, licence, and dependencies?
NAMESPACEREADME.mdDESCRIPTION.RbuildignoreAnswer: 3) DESCRIPTION is the metadata file. NAMESPACE is auto-generated from your roxygen2 comments.
Which file should you NEVER edit by hand?
DESCRIPTIONNAMESPACEREADME.mdR/myfunction.RAnswer: 2) NAMESPACE is managed by devtools::document(). Manual edits get overwritten next time you regenerate docs.
Which package is for setting up a project, and which is for doing development (build, load, test)?
usethis for setup, devtools for doingdevtools for setup, usethis for doingroxygen2 for bothAnswer: 1) usethis scaffolds files (use_r, use_package, use_data_raw); devtools runs the dev loop (load_all, document, test, check).
Why should you never write library(ggplot2) inside a package function?
library() calls inside functionsDESCRIPTION Imports and call ggplot2::aes() with ::library() is slower than require()Answer: 2) Packages declare dependencies in DESCRIPTION and call imported functions with ::.
What does devtools::load_all() do?
DESCRIPTIONAnswer: 2) load_all() is the dev equivalent of library(). It instantly reflects code changes without installing.
What does the @export roxygen tag do?
.rda filelibrary(yourpkg)Answer: 3) Without @export, a function stays internal — usable inside the package but not after loading it (unless called via yourpkg:::fn()).
Roxygen2 documentation comments must start with which prefix?
##'##//Answer: 2) #' tells devtools::document() to parse the line. Just # is a code comment and ignored.
In a data package, where do raw data scripts go vs the cleaned data they produce?
R/data-raw/; cleaned .rda files in data/data/; cleaned files in data-raw/tests/Answer: 2) usethis::use_data_raw() sets up the script folder; the script ends with usethis::use_data(your_object) to save the cleaned .rda into data/.