R in Pharma 2022 CI/CD workshop repository.
Full workshop video available here: https://www.youtube.com/watch?v=OcNzurpCCpY
Presentation video available here: https://www.youtube.com/watch?v=8HPpdv8crHo
Exercises
Exercise 1
Fix issues identified by R CMD check workflow.
Click here for a hint π
A unit test is failing forhello.R.
Click here for the solution β
The expected message should beWelcome to the R/Pharma CI/CD workshop! (R/Pharma is missing from the message) in the tests/testthat/test-hello.R file.
Exercise 2
Fix broken links after implementing the Check URLs workflow.
Click here for a hint π
An R/Pharma link is broken in theNEWS.md file.
Click here for the solution β
The rinpharma website domain is incorrectly set as.xcom. It should be .com.
Exercise 3
Find and fix all spelling errors determined by the Spellcheck workflow.
Click here for a hint π
One or more words are misspelled in theNEWS.md file.
Click here for the solution β
The wordlink is misspelled as linke in NEWS.md. The word strangephrase should be strange phrase in NEWS.md. Fix the spelling first in the NEWS.md file. Next, simply run spelling::update_wordlist(confirm=βYesβ) to add technical jargon to the wordlist.
Exercise 4
Fix code style errors implementing the Style workflow.
Click here for a hint π
Thereβs a minor style issue in theR/hello.R file.
Click here for the solution β
Simply runstyler::style_file(βR/hello.Rβ) to automatically style the file.
Exercise 5
Reduce the cyclomatic complexity identified by the Lint Code Base workflow.
Click here for a hint π
The issue is manifested in theR/hello.R file.
Click here for the solution β
Reduce the number of if statements to reduce the cyclomatic complexity in theR/hello.R file for the linter_ex() function. Run styler::style_file(βR/hello.Rβ) to fix style issues, if any. Then, run lintr::lint_package() iteratively to determine whether the issue has been resolved.
Exercise 6
Update man pages based on the errors reported by the ROxygen workflow.
Click here for a hint π
Function documentation is not up-to-date forR/cicdworkshop-package.R and the linter_ex() function.
Click here for the solution β
Simply runroxygen2::roxygenize(β.β, roclets = c(βrdβ, βcollateβ, βnamespaceβ)) or devtools::document() to automatically update all man pages.
Exercise 7
Increase code coverage for the package.
Click here for a hint π
Add a simple unit test for thelinter_ex() function defined in the R/hello.R file.
Click here for the solution β
Run covr::package_coverage() to note the current code coverage.
In the tests/testthat/test-hello.R file, add the following test:
test_that("linter_ex is surprised", {
expect_message(
linter_ex("lint"),
"^Whoa!\\n"
)
})
Run tests locally by executing devtools::test() to make sure that the tests succeed.
covr::package_coverage() to see that the code coverage has increased.