Title: | Create, Build and Maintain Packages |
---|---|
Description: | Helper functions for package creation, building and maintenance. Designed to work with a build system such as 'GNU make' or package 'fakemake' to help you to conditionally work through the stages of package development (such as spell checking, linting, testing, before building and checking a package). |
Authors: | Andreas Dominik Cullmann [aut, cre] |
Maintainer: | Andreas Dominik Cullmann <[email protected]> |
License: | BSD_2_clause + file LICENSE |
Version: | 1.15.2.9000 |
Built: | 2025-02-15 04:57:08 UTC |
Source: | https://gitlab.com/fvafrcu/packager |
Helper functions for package creation, building and maintenance, heavily borrowing from devtools 1.13.3.
You will find the details invignette("An_Introduction_to_packager", package = "packager")
.
devtools version
(devtools::build_manual
) does not run
roxygen first and by defaults puts it in ../ instead of .Rcheck
build_manual( path = ".", output_directory = NULL, roxygenise = TRUE, verbose = TRUE )
build_manual( path = ".", output_directory = NULL, roxygenise = TRUE, verbose = TRUE )
path |
Path to the package. |
output_directory |
Where to put the manual. Defaults to the Rcheck directory. |
roxygenise |
Run roxygen first? |
verbose |
Be verbose? |
Invisibly
the value of the call to
R CMD Rd2pdf
.
This is a wrapper to
callr::rcmd_safe("check")
,
similar to, but leaner than
rcmdcheck::rcmdcheck
. While
the latter parses the output of rcmd_safe
and uses
clisymbols in the callback, we here just return bare output and use
writeLines
as callback. This should result in a screen display
that is identical to the output of R CMD check
.
check_archive(path, cmdargs = NULL) check_archive_as_cran(path)
check_archive(path, cmdargs = NULL) check_archive_as_cran(path)
path |
Path to the package archive. |
cmdargs |
Command line arguments (see
|
A list with standard output, standard error
and exit status of the check.
(see callr::rcmd
).
check_archive_as_cran
is a convenience Wrapper to
check_archive
.
Other maintenance functions:
check_codetags()
,
check_cyclomatic_complexity()
,
check_news()
,
check_usage()
,
get_check_status()
Other maintenance functions:
check_codetags()
,
check_cyclomatic_complexity()
,
check_news()
,
check_usage()
,
get_check_status()
## Not run: package_path <- file.path(tempdir(), "fakepack") usethis::create_package(path = package_path) file.copy(system.file("templates", "throw.R", package = "fakemake"), file.path(package_path, "R")) roxygen2::roxygenize(package_path) print(tarball <- get_pkg_archive_path(package_path)) pkgbuild::build(pkg = package_path, path = package_path) print(check_archive(tarball)) ## End(Not run)
## Not run: package_path <- file.path(tempdir(), "fakepack") usethis::create_package(path = package_path) file.copy(system.file("templates", "throw.R", package = "fakemake"), file.path(package_path, "R")) roxygen2::roxygenize(package_path) print(tarball <- get_pkg_archive_path(package_path)) pkgbuild::build(pkg = package_path, path = package_path) print(check_archive(tarball)) ## End(Not run)
You do use code tags (see PEP 350 for example)? This function searches for files under a directory containing such tags.
check_codetags( path = ".", exclude_pattern = "\\.Rcheck/", include_pattern = "\\.[Rr]$|\\.[Rr]md$", pattern = "XXX:|FIXME:|TODO:" )
check_codetags( path = ".", exclude_pattern = "\\.Rcheck/", include_pattern = "\\.[Rr]$|\\.[Rr]md$", pattern = "XXX:|FIXME:|TODO:" )
path |
to a directory, typically a package root. |
exclude_pattern |
A pattern for exclusions based on the file names.
Stronger than |
include_pattern |
A pattern for inclusions based on the file names. |
pattern |
The pattern to search for. |
A character vector of hits.
Other maintenance functions:
check_archive()
,
check_cyclomatic_complexity()
,
check_news()
,
check_usage()
,
get_check_status()
dir <- system.file("runit_tests", package = "packager") r <- check_codetags(dir) print(r)
dir <- system.file("runit_tests", package = "packager") r <- check_codetags(dir) print(r)
Cyclomatic Complexity
Run
cyclocomp_package_dir
on the
package throwing an error when the maximum complexity is exceeded.
check_cyclomatic_complexity(path = ".", max_complexity = 10)
check_cyclomatic_complexity(path = ".", max_complexity = 10)
path |
Path to the package directory (see
|
max_complexity |
The maximum |
Invisibly TRUE
if
maximum cyclomatic complexity
is not exceeded, throws an error
otherwise.
Other maintenance functions:
check_archive()
,
check_codetags()
,
check_news()
,
check_usage()
,
get_check_status()
## Not run: # download and untar sources of some archived package package <- "excerptr" root <- paste0("http://cran.r-project.org/src/contrib/Archive/", package) version <- "1.0.0" tarball <- paste0(paste(package, version, sep = "_"), ".tar.gz") remote_tarball <- paste(root, tarball, sep = "/") local_tarball <- file.path(tempdir(), tarball) utils::download.file(remote_tarball, local_tarball) utils::untar(local_tarball, exdir = tempdir()) res <- tryCatch(check_cyclomatic_complexity(path = file.path(tempdir(), package)), error = identity) print(res) ## End(Not run)
## Not run: # download and untar sources of some archived package package <- "excerptr" root <- paste0("http://cran.r-project.org/src/contrib/Archive/", package) version <- "1.0.0" tarball <- paste0(paste(package, version, sep = "_"), ".tar.gz") remote_tarball <- paste(root, tarball, sep = "/") local_tarball <- file.path(tempdir(), tarball) utils::download.file(remote_tarball, local_tarball) utils::untar(local_tarball, exdir = tempdir()) res <- tryCatch(check_cyclomatic_complexity(path = file.path(tempdir(), package)), error = identity) print(res) ## End(Not run)
Compare your ‘NEWS.md’ file to the 'Version' entry in DESCRIPTION.
check_news(path = ".")
check_news(path = ".")
path |
Path to the package directory (see
|
Invisibly TRUE
if
‘NEWS.md’ matches DESCRIPTION, throws an error otherwise.
Other maintenance functions:
check_archive()
,
check_codetags()
,
check_cyclomatic_complexity()
,
check_usage()
,
get_check_status()
checkUsagePackage
This is just a convenience wrapper to checkUsagePackage
(which
needs loading of the [development version of the] package).
check_usage(path = ".")
check_usage(path = ".")
path |
Path to the package directory (see
|
A character vector of issues found by
checkUsagePackage
.
Other maintenance functions:
check_archive()
,
check_codetags()
,
check_cyclomatic_complexity()
,
check_news()
,
get_check_status()
This is just a wrapper to create a package and
infect it using infect
.
create(path, force = TRUE, ...)
create(path, force = TRUE, ...)
path |
The package to create. |
force |
Recursively |
... |
Arguments to be passed to |
path <- file.path(tempdir(), "myFirstPackage") packager::create(path = path, fakemake = "roxygen2") list.files(path, recursive = TRUE) ## Not run: if (require("roxygen2")) { ml <- packager::get_package_makelist(is_cran = TRUE) d <- file.path(tempdir(), "somePackage") dir.create(d) packager::create(d, fakemake = FALSE, fakemake = FALSE) withr::with_dir(d, fakemake::make("check", ml)) check_log <- file.path(d, "log", "check.Rout") status <- packager::get_check_status(check_log) RUnit::checkEqualsNumeric(status[["status"]][["errors"]], 0) list.files(d, recursive = TRUE) unlink(d, recursive = TRUE) } ## End(Not run)
path <- file.path(tempdir(), "myFirstPackage") packager::create(path = path, fakemake = "roxygen2") list.files(path, recursive = TRUE) ## Not run: if (require("roxygen2")) { ml <- packager::get_package_makelist(is_cran = TRUE) d <- file.path(tempdir(), "somePackage") dir.create(d) packager::create(d, fakemake = FALSE, fakemake = FALSE) withr::with_dir(d, fakemake::make("check", ml)) check_log <- file.path(d, "log", "check.Rout") status <- packager::get_check_status(check_log) RUnit::checkEqualsNumeric(status[["status"]][["errors"]], 0) list.files(d, recursive = TRUE) unlink(d, recursive = TRUE) } ## End(Not run)
makelist
Suitable for Packages with packager
Provide a makelist
Suitable for Packages with packager
get_package_makelist(is_cran = FALSE, gitlab_token = NULL)
get_package_makelist(is_cran = FALSE, gitlab_token = NULL)
is_cran |
Streamline |
gitlab_token |
A private gitlab token. Used to query logs on https://about.gitlab.com. |
A list for
fakemake::make
.
ml <- packager::get_package_makelist() cbind(lapply(ml, function(x) x[["target"]]), lapply(ml, function(x) x[["alias"]])) cl <- packager::get_package_makelist(is_cran = TRUE) setdiff(sapply(ml, function(x) x[["target"]]), sapply(cl, function(x) x[["target"]]))
ml <- packager::get_package_makelist() cbind(lapply(ml, function(x) x[["target"]]), lapply(ml, function(x) x[["alias"]])) cl <- packager::get_package_makelist(is_cran = TRUE) setdiff(sapply(ml, function(x) x[["target"]]), sapply(cl, function(x) x[["target"]]))
See
fritools::get_package_version
.
get_package_version(x, lib_loc = NULL)
get_package_version(x, lib_loc = NULL)
x |
A character giving the package name. |
lib_loc |
See argument |
A character giving the package version.
The archive file does not have to exist. Use
file.exists(get_pkg_archive_path())
to test existence.
get_pkg_archive_path(path = ".", absolute = TRUE)
get_pkg_archive_path(path = ".", absolute = TRUE)
path |
Path to the package directory (see
|
absolute |
Return the absolute path? |
Path to the package's archive file.
package_path <- file.path(tempdir(), "anRpackage") usethis::create_package(path = package_path) print(tarball <- get_pkg_archive_path(package_path)) file.exists(tarball)
package_path <- file.path(tempdir(), "anRpackage") usethis::create_package(path = package_path) print(tarball <- get_pkg_archive_path(package_path)) file.exists(tarball)
Much like git commit -am"M"
, where M
is the
message
.
git_add_commit( path, message = "Uncommented Changes: Backing Up", untracked = FALSE )
git_add_commit( path, message = "Uncommented Changes: Backing Up", untracked = FALSE )
path |
The path to the repository. |
message |
The commit message to use. |
untracked |
Add files not tracked yet before committing? |
The return value of
gert::git_commit_all
.
Other git wrappers:
git_tag()
Show a Git Diff for a File
git_diff(x, path, verbose = TRUE)
git_diff(x, path, verbose = TRUE)
x |
The path to the file relative to the repository given by
|
path |
The path to the git repository. |
verbose |
Be verbose? This is the main purpose of this tiny little wrapper! |
The git diff.
This is basically the same as git tag -a T -m M
where T is the
version read from the package's DESCRIPTION file and M is given by
message
(see below).
git_tag(path = ".", tag_uncommited = FALSE, message = "CRAN release")
git_tag(path = ".", tag_uncommited = FALSE, message = "CRAN release")
path |
Path to the package. |
tag_uncommited |
Tag if there are uncommitted changes? |
message |
The tag message to be used. |
FALSE
or the value of
gert::git_tag_list
.
Other git wrappers:
git_add_commit()
Add a variety of extensions to a package (skeleton) and run
fakemake::make
on
it.
infect(path, fakemake = "check", git_add_and_commit = TRUE, ...)
infect(path, fakemake = "check", git_add_and_commit = TRUE, ...)
path |
Path to the package directory (see
|
fakemake |
The |
git_add_and_commit |
Add and commit changes in git? |
... |
Arguments to be passed to |
## Not run: if (require("roxygen2")) { path <- file.path(tempdir(), "mySecondPackage") usethis::create_package(path = path, open = FALSE) l1 <- list.files(path, recursive = TRUE) packager::infect(path = path, fakemake = "roxygen2", fakemake = FALSE) l2 <- list.files(path, recursive = TRUE) print(l1); print(l2) unlink(path, recursive = TRUE) } ## End(Not run)
## Not run: if (require("roxygen2")) { path <- file.path(tempdir(), "mySecondPackage") usethis::create_package(path = path, open = FALSE) l1 <- list.files(path, recursive = TRUE) packager::infect(path = path, fakemake = "roxygen2", fakemake = FALSE) l2 <- list.files(path, recursive = TRUE) print(l1); print(l2) unlink(path, recursive = TRUE) } ## End(Not run)
lintr::lint_package
lintr now runs cyclocomp, which we use independently and we don't
want to run it twice. So this is just a wrapper to
codelintr::lint_package where we hardcode the
exclusion of unwanted linters (more may be added to lintr) so other
packages using packager's ‘Makefile’ or
get_package_makelist
don't have to care of changes to the
default linters in lintr.
lint_package(path)
lint_package(path)
path |
The path to the package, passed to
|
See the return value of
lintr::lint_package
.
submit
reads a file ‘cran-comments.md’. This
function provides a template based on your R version, your
R CMD check
output and
the package's ‘NEWS.md’.
provide_cran_comments( check_log = NULL, path = ".", initial = FALSE, write_to_file = TRUE, private_token = NULL, name = NA, proxy = NULL )
provide_cran_comments( check_log = NULL, path = ".", initial = FALSE, write_to_file = TRUE, private_token = NULL, name = NA, proxy = NULL )
check_log |
Deprecated, will be removed in a future release. The local R CMD check log is now supposed to live be 'log/check.(log|Rout)'. |
path |
Path to the package directory (see
|
initial |
Is this an initial submission? |
write_to_file |
Do write the comment to ‘cran-comment.md’? |
private_token |
Provide a private token to access https://about.gitlab.com. |
name |
The name to sign with, if NA, the given name of the package maintainer as stated in file DESCRIPTION is used. |
proxy |
A proxy to use. |
Character vector containing the CRAN comments, which are written to ‘cran-comments.md’ (see Note).
By default this function writes to disk as side effect.
## Not run: if (Sys.info()[["nodename"]] == "fvafrdebianCU") { gitlab_token <- readLines(file.path("~", ".gitlab_private_token.txt")) proxy <- httr::use_proxy("10.127.255.17", 8080) comments <- provide_cran_comments(path = ".", write_to_file = TRUE, private_token = gitlab_token, proxy = proxy) } else { gitlab_token <- readLines(file.path("~", ".gitlab_private_token.txt")) comments <- provide_cran_comments(path = ".", write_to_file = TRUE, private_token = gitlab_token) } cat(comments, sep = "") ## End(Not run)
## Not run: if (Sys.info()[["nodename"]] == "fvafrdebianCU") { gitlab_token <- readLines(file.path("~", ".gitlab_private_token.txt")) proxy <- httr::use_proxy("10.127.255.17", 8080) comments <- provide_cran_comments(path = ".", write_to_file = TRUE, private_token = gitlab_token, proxy = proxy) } else { gitlab_token <- readLines(file.path("~", ".gitlab_private_token.txt")) comments <- provide_cran_comments(path = ".", write_to_file = TRUE, private_token = gitlab_token) } cat(comments, sep = "") ## End(Not run)
This is a stripped version of devtools'
release function
, omitting most of the
interactive checks.
submit( path = ".", stop_on_git = TRUE, stop_on_devel = TRUE, force = FALSE, verbose = TRUE, consider_untracked = TRUE ) release( path = ".", stop_on_git = TRUE, stop_on_devel = TRUE, force = FALSE, verbose = TRUE, consider_untracked = TRUE )
submit( path = ".", stop_on_git = TRUE, stop_on_devel = TRUE, force = FALSE, verbose = TRUE, consider_untracked = TRUE ) release( path = ".", stop_on_git = TRUE, stop_on_devel = TRUE, force = FALSE, verbose = TRUE, consider_untracked = TRUE )
path |
The package's root directory. |
stop_on_git |
Stop if git has uncommitted changes or is not synced with the origin? |
stop_on_devel |
Stop if the package has a development version? (That is, a four part version.) |
force |
Skip user interaction? |
verbose |
Be verbose? |
consider_untracked |
Consider untracked files if
consider_untracked is |
release
is just a link to submit
as
release
is the original function from
devtools.
This is verbatim copy of git commit
a5e5805ecd630ebc46e080bd78ebcf32322efe3c
of usethis.
‘.Rbuildignore’ has a regular expression on each line, but it's
usually easier to work with specific file names. By default, will (crudely)
turn filenames into regular expressions that will only match these
paths. Repeated entries will be silently removed.
use_build_ignore(files, escape = TRUE, pkg = ".")
use_build_ignore(files, escape = TRUE, pkg = ".")
files |
Paths of files. |
escape |
If |
pkg |
Path to the package directory (see
|
Nothing, called for its side effect.
This is much like
usethis::use_dev_version
, but their
conventions keep changing.
use_dev_version(path = ".", force = FALSE) use_devel_version(path = ".", force = FALSE)
use_dev_version(path = ".", force = FALSE) use_devel_version(path = ".", force = FALSE)
path |
Path to the package directory (see
|
force |
Set to |
From usethis::use_dev_version
,
the name was use_dev_version
, but use_devel_version
seems
more natural. But it is just a link.
Create a directory.
this is verbatim copy of git commit
a5e5805ecd630ebc46e080bd78ebcf32322efe3c
of usethis.
use_directory(path, ignore = FALSE, pkg = ".")
use_directory(path, ignore = FALSE, pkg = ".")
path |
Path of the directory to create, relative to the project. |
ignore |
Add the directory to ‘.Rbuildignore’? |
pkg |
Path to the package directory (see
|