Introduction
To err is human - Alexander Pope (1711)
err is a light-weight R package to produce customizable number and object sensitive error and warning messages.
Demonstration
Object Sensitive
The co functions produce object sensitive strings.
library(err)
fox <- c("The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog")
co(fox)
#> [1] "fox has 9 values: 'The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'"
co(fox[1])
#> [1] "fox[1] has 1 value: 'The'"
co(fox[0])
#> [1] "fox[0] has 0 values"
co(fox, nlots = 5)
#> [1] "fox has 9 values: 'The', 'quick', 'brown', ..., 'dog'"Customizable
The object sensitive strings are fully customized.
one <- "darn! the vector %o of length %n has the following value: %c"
none <- "phew! vector %o is empty"
some <- "rats! vector %o has the following %n element%s: %c"
lots <- "really?! the %n elements of vector %o are too numerous to print"
co(fox[0], one = one, none = none, some = some, lots = lots, nlots = 5)
#> [1] "phew! vector fox[0] is empty"
co(fox[1], one = one, none = none, some = some, lots = lots, nlots = 5)
#> [1] "darn! the vector fox[1] of length 1 has the following value: 'The'"
co(fox[1:3], one = one, none = none, some = some, lots = lots, nlots = 5)
#> [1] "rats! vector fox[1:3] has the following 3 elements: 'The', 'quick', 'brown'"
co(fox[1:5], one = one, none = none, some = some, lots = lots, nlots = 5)
#> [1] "really?! the 5 elements of vector fox[1:5] are too numerous to print"The following sprintf-like types can be used in the custom messages:
-
%c: the object as a comma separated list (produced by accfunction) -
%n: the length of the object -
%o: the name of the object -
%s: ‘s’ if n != 1 otherwise ’’ -
%r: ‘are’ if n != 1 otherwise ‘is’
And there are various formatting options
co(fox[1:6], conjunction = "or", bracket = "|", oxford = TRUE, ellipsis = 5)
#> [1] "fox[1:6] has 6 values: |The|, |quick|, |brown|, ..., or |over|"Installation
To install the latest release version from CRAN
To install the latest development version from GitHub
Contribution
Please report any issues.
Pull requests are always welcome.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Code of Conduct
Please note that the err project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
