Title: | Advice on R Package Building |
---|---|
Description: | Give advice about good practices when building R packages. Advice includes functions and syntax to avoid, package structure, code complexity, code formatting, etc. |
Authors: | Mark Padgham [aut, cre] , Ascent Digital Services UK Limited [cph] (MangoTheCat), Karina Marks [aut] (KarinaMarks), Daniel de Bortoli [aut] (ddbortoli), Gabor Csardi [aut], Hannah Frick [aut], Owen Jones [aut] (owenjonesuob), Hannah Alexander [aut], Ana Simmons [ctb] (anasimmons), Fabian Scheipl [ctb] (fabian-s) |
Maintainer: | Mark Padgham <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.5.9000 |
Built: | 2024-11-18 15:23:55 UTC |
Source: | https://github.com/ropensci-review-tools/goodpractice |
Give advice about good practices when building R packages. Advice includes functions and syntax to avoid, package structure, code complexity, code formatting, etc.
Maintainer: Mark Padgham [email protected] (ORCID)
Authors:
Karina Marks [email protected] (KarinaMarks)
Daniel de Bortoli (ddbortoli)
Gabor Csardi [email protected]
Hannah Frick [email protected]
Owen Jones [email protected] (owenjonesuob)
Hannah Alexander [email protected]
Other contributors:
Ascent Digital Services UK Limited (MangoTheCat) [copyright holder]
Ana Simmons [email protected] (anasimmons) [contributor]
Fabian Scheipl (fabian-s) [contributor]
Useful links:
Report bugs at https://github.com/ropensci-review-tools/goodpractice/issues
List the names of all checks
all_checks()
all_checks()
Character vector of checks
List all checks performed
checks(gp)
checks(gp)
gp |
|
Character vector of check names.
Other API:
failed_checks()
,
results()
path <- system.file("bad1", package = "goodpractice") # run a subset of all checks available g <- gp(path, checks = all_checks()[3:16]) checks(g)
path <- system.file("bad1", package = "goodpractice") # run a subset of all checks available g <- gp(path, checks = all_checks()[3:16]) checks(g)
Defining custom preparations and checks
make_prep(name, func) make_check(description, check, gp, ...)
make_prep(name, func) make_check(description, check, gp, ...)
name |
Name of the preparation function. |
func |
A function that takes two arguments:
The |
description |
A description of the check. |
check |
A function that takes the |
gp |
A short description of what is good practice. |
... |
Further arguments. Most important: A |
make_prep()
: Create a preparation function
make_check()
: Create a check function
# make a preparation function url_prep <- make_prep( name = "desc", func = function(path, quiet) desc::description$new(path) ) # and the corresponding check function url_chk <- make_check( description = "URL field in DESCRIPTION", tags = character(), preps = "desc", gp = "have a URL field in DESCRIPTION", check = function(state) state$desc$has_fields("URL") ) # use together in gp(): # (note that you have to list the name of your custom check in # the checks-argument as well....) bad1 <- system.file("bad1", package = "goodpractice") res <- gp(bad1, checks = c("url", "no_description_depends"), extra_preps = list("desc" = url_prep), extra_checks = list("url" = url_chk))
# make a preparation function url_prep <- make_prep( name = "desc", func = function(path, quiet) desc::description$new(path) ) # and the corresponding check function url_chk <- make_check( description = "URL field in DESCRIPTION", tags = character(), preps = "desc", gp = "have a URL field in DESCRIPTION", check = function(state) state$desc$has_fields("URL") ) # use together in gp(): # (note that you have to list the name of your custom check in # the checks-argument as well....) bad1 <- system.file("bad1", package = "goodpractice") res <- gp(bad1, checks = c("url", "no_description_depends"), extra_preps = list("desc" = url_prep), extra_checks = list("url" = url_chk))
Export failed checks to JSON
export_json(gp, file, pretty = FALSE)
export_json(gp, file, pretty = FALSE)
gp |
|
file |
Output connection or file. |
pretty |
Whether to pretty-print the JSON. |
Names of the failed checks
failed_checks(gp)
failed_checks(gp)
gp |
|
Names of the failed checks.
Other API:
checks()
,
results()
path <- system.file("bad1", package = "goodpractice") # run a subset of all checks available g <- gp(path, checks = all_checks()[3:16]) failed_checks(g)
path <- system.file("bad1", package = "goodpractice") # run a subset of all checks available g <- gp(path, checks = all_checks()[3:16]) failed_checks(g)
Note that not all checks refer to the source code.
For these the result will be NULL
.
failed_positions(gp)
failed_positions(gp)
gp |
|
For the ones that do, the results is a list, one for each failure.
Since the same check can fail multiple times. A single failure
is a list with entries: filename
, line_number
,
column_number
, ranges
. ranges
is a list of
pairs of start and end positions for each line involved in the
check.
A list of lists of positions. See details below.
To see the results, just print it to the screen.
gp( path = ".", checks = all_checks(), extra_preps = NULL, extra_checks = NULL, quiet = TRUE )
gp( path = ".", checks = all_checks(), extra_preps = NULL, extra_checks = NULL, quiet = TRUE )
path |
Path to a package root. |
checks |
Character vector, the checks to run. Defaults to
all checks. Use |
extra_preps |
Custom preparation functions. See
|
extra_checks |
Custom checks. See |
quiet |
Whether to suppress output from the preparation
functions. Note that not all preparation functions produce output,
even if this option is set to |
A goodpractice object that you can query
with a simple API. See results
to start.
path <- system.file("bad1", package = "goodpractice") # run a subset of all checks available g <- gp(path, checks = all_checks()[3:16]) g
path <- system.file("bad1", package = "goodpractice") # run a subset of all checks available g <- gp(path, checks = all_checks()[3:16]) g
Print goodpractice results
## S3 method for class 'goodPractice' print(x, positions_limit = 5, ...)
## S3 method for class 'goodPractice' print(x, positions_limit = 5, ...)
x |
Object of class |
positions_limit |
How many positions to print at most. |
... |
Unused, for compatibility with |
Return all check results in a data frame
results(gp)
results(gp)
gp |
|
Data frame, with columns:
check |
The name of the check. |
result |
Logical, whether it has failed or not. |
Other API:
checks()
,
failed_checks()
path <- system.file("bad1", package = "goodpractice") # run a subset of all checks available g <- gp(path, checks = all_checks()[3:16]) results(g)
path <- system.file("bad1", package = "goodpractice") # run a subset of all checks available g <- gp(path, checks = all_checks()[3:16]) results(g)