Maintaining Packages Using fakemake
Our brand new package veryImportantPackage is checked into git already:
## Local: master /tmp/RtmpqNOvH8/veryImportantPackage
## Head: [20d99fe] 2020-09-28: Packager Changes
##
## Branches: 1
## Tags: 0
## Commits: 16
## Contributors: 1
## Stashes: 0
## Ignored files: 0
## Untracked files: 0
## Unstaged files: 0
## Staged files: 0
##
## Latest commits:
## [20d99fe] 2020-09-28: Packager Changes
## [bb8c0db] 2020-09-28: Adding `man-roxygen/return_invisibly_null.R` from template `return_invisibly_null.R` of package` packager`.
## [4656134] 2020-09-28: Adding `make.R` from template `make.R` of package` packager`.
## [3cab7d1] 2020-09-28: Adding `inst/runit_tests/runit-throw.R` from template `runit-throw.R` of package` packager`.
## [813b479] 2020-09-28: Adding `tests/runit.R` from template `runit.R` of package` packager`.
## working directory clean
but we have so far only built the documentation from the roxygen
comments:
## [1] "roxygen2.Rout"
So we get a makelist
and look at its targets and aliases:
ml <- packager::get_package_makelist(is_cran = TRUE)
cbind(lapply(ml, function(x) x[["target"]]),
lapply(ml, function(x) x[["alias"]]))
## [,1] [,2]
## [1,] "log/roxygen2.Rout" "roxygen2"
## [2,] "log/spell.Rout" "spell"
## [3,] "log/cleanr.Rout" "cleanr"
## [4,] "log/lintr.Rout" "lint"
## [5,] "log/covr.Rout" "covr"
## [6,] "packager::get_pkg_archive_path(absolute = FALSE)" "build"
## [7,] "log/check.Rout" "check"
## [8,] ".log.Rout" ".log"
## [9,] "log/testthat.Rout" "testthat"
## [10,] "log/vignettes.Rout" "vignettes"
## [11,] "log/codetags.Rout" "codetags"
## [12,] "log/news.Rout" "news"
## [13,] "log/usage.Rout" "usage"
## [14,] "log/winbuilder.Rout" "winbuilder"
## [15,] "log/cran_comments.Rout" "cran_comments"
## [16,] "log/check_as_cran.Rout" "check_as_cran"
## [17,] "log/submit.Rout" "submit"
Building the Package
We choose to build the package:
## Warning in eval(parse(text = make_list[[index]][["code"]])):
## Spell check failed, see /tmp/RtmpqNOvH8/veryImportantPackage/log/spell.Rout for details.
## [1] "log/cleanr.Rout" "log/codetags.Rout"
## [3] "log/covr.Rout" "log/lintr.Rout"
## [5] "log/news.Rout" "log/spell.Rout"
## [7] "log/testthat.Rout" "log/usage.Rout"
## [9] "log/vignettes.Rout" "veryImportantPackage_0.1.0.tar.gz"
We note the warning
## diff --git a/.Rbuildignore b/.Rbuildignore
## index 869d606..60acd7f 100644
## --- a/.Rbuildignore
## +++ b/.Rbuildignore
## @@ -15,3 +15,5 @@
## ^man-roxygen/return_invisibly_null\.R$
## ^\.log\.Rout$
## ^log$
## +^doc$
## +^Meta$
and see that now there are untracked files in our package’s log directory and that some files changed.
## Untracked files:
## Untracked: log/build.Rout
## Untracked: log/cleanr.Rout
## Untracked: log/codetags.Rout
## Untracked: log/covr.Rout
## Untracked: log/lintr.Rout
## Untracked: log/news.Rout
## Untracked: log/spell.Rout
## Untracked: log/testthat.Rout
## Untracked: log/usage.Rout
## Untracked: log/vignettes.Rout
##
## Unstaged changes:
## Modified: .Rbuildignore
## Modified: .gitignore
## diff --git a/.Rbuildignore b/.Rbuildignore
## index 869d606..60acd7f 100644
## --- a/.Rbuildignore
## +++ b/.Rbuildignore
## @@ -15,3 +15,5 @@
## ^man-roxygen/return_invisibly_null\.R$
## ^\.log\.Rout$
## ^log$
## +^doc$
## +^Meta$
After inspecting the change, we commit:
withr::with_dir(path, packager::git_add_commit(path = ".", untracked = TRUE,
message = "make build"))
## [270fdbd] 2020-09-28: make build
## working directory clean
Checking the Package
So now we want the check the package:
## [1] "log/cleanr.Rout" "log/covr.Rout"
## [3] "log/lintr.Rout" "log/testthat.Rout"
## [5] "veryImportantPackage_0.1.0.tar.gz" "log/check.Rout"
We again see new files and changes to old files.
## Untracked files:
## Untracked: log/check.Rout
##
## Unstaged changes:
## Modified: log/build.Rout
## Modified: log/testthat.Rout
Note that the RUnit
test files are run while checking the tarball, hence we see output from RUnit
in our log directory.
We assume that we passed the check:
##
## Status: 1 WARNING
## See
## ‘/tmp/RtmpqNOvH8/veryImportantPackage/veryImportantPackage.Rcheck/00check.log’
## for details.
check_log <- file.path(path, "log", "check.Rout")
status <- packager::get_check_status(check_log)
RUnit::checkEqualsNumeric(status[["status"]][["errors"]], 0)
## [1] TRUE
and commit again
withr::with_dir(path, packager::git_add_commit(path = ".", untracked = TRUE,
message = "make check"))
## [9001d52] 2020-09-28: make check
If we choose to rerun the check without touching any files “down the make chain” (i.e. no files that any of our make targets depend on), we see there’s nothing to be done:
## NULL
## user system elapsed
## 0.741 0.024 0.768
This is the big difference between running the check via fakemake
with a set of dependencies (set up with packager
) and running the check (be it using R CMD check
or rcmdcheck::rcmdcheck
or its wrapper devtools::check
) unconditionally: the latter method rebuilds and checks the whole package every time. This is why I wrote packager
and fakemake
.
Submitting the Package
Now we would like to submit our package to CRAN (which we will not do here, but we want to!) We provide comments to CRAN:
## R CMD check results
## 0 errors | 1 warning | 0 notes
## Warning in get_gitlab_info(path = path, private_token = private_token): You need
## a private token to access gitlab.
## [1] "log/cran_comments.Rout"
## Dear CRAN Team,
## this is a resubmission of package 'veryImportantPackage'. I have added the following changes:
##
## * Added a `NEWS.md` file to track changes to the package.
##
##
## Please upload to CRAN.
## Best, Your
##
## # Package veryImportantPackage 0.1.0
##
## Reporting is done by packager version 1.5.0
##
## ## Test environments
## - R Under development (unstable) (2020-09-23 r79248)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Devuan GNU/Linux 3 (beowulf)
## NA
## - win-builder (devel)
##
## ## Local test results
## - Testthat:
## OK: 1, Failed: 0, Warnings: 1, Skipped: 0
## - Coverage by covr:
##
##
## ## Local meta results
## - lintr:
## found 1 lints in 32 lines of code (a ratio of 0.0312).
## - cleanr:
## found 0 dreadful things about your code.
## - codetools::checkUsagePackage:
## found 0 issues.
## - devtools::spell_check:
## found 2 unkown words.
After editing the contents we feel ready to submit:
## Error in packager::submit(path) : You have uncommitted changes.
Oops: we need to commit git first:
## [a158c19] 2020-09-28: prepare for CRAN
## working directory clean
Now we try and fail again, because this vignette is built in batch mode and there’s a security query which then fails:
## Warning in packager::submit(path): You have no upstream!
## Ready to submit?Error in utils::menu(qs[rand]) : menu() cannot be used non-interactively
Should you run this code interactively, you will be prompted for the security query (as you might be used from devtools::release()
). Best you know how to write R extensions and the CRAN policies.
Anyway, we might want to tag the current commit and commence developing our package:
## [a158c1] 0.1.0
## Package version bumped from '0.1.0' to '0.1.0.9000'
## [4898797] 2020-09-28: Using Developement Version
## Version
## "0.1.0.9000"
## # veryImportantPackage 0.1.0.9000
##
## * FIXME
##
## # veryImportantPackage 0.1.0
##
## * Added a `NEWS.md` file to track changes to the package.
This is close to the workflow I have been using for most of my packages, substituting fakemake
with GNU make whenever possible.