Title: | Customizable Object Sensitive Messages |
---|---|
Description: | Messages should provide users with readable information about R objects without flooding their console. 'cc()' concatenates vector and data frame values into a grammatically correct string using commas, an ellipsis and conjunction. 'cn()' allows the user to define a string which varies based on a count. 'co()' combines the two to produce a customizable object aware string. The package further facilitates this process by providing five 'sprintf'-like types such as '%n' for the length of an object and '%o' for its name as well as wrappers for pasting objects and issuing errors, warnings and messages. |
Authors: | Joe Thorley [aut, cre] , James Dunham [aut] |
Maintainer: | Joe Thorley <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0.9000 |
Built: | 2024-11-01 16:18:59 UTC |
Source: | https://github.com/poissonconsulting/err |
Concatenates object values into a string with each value separated by a comma and possibly the last value separated by a conjunction.
## Default S3 method: cc( object, conjunction = NULL, bracket = "", ellipsis = 10, oxford = FALSE, ... ) ## S3 method for class 'character' cc( object, conjunction = NULL, bracket = "'", ellipsis = 10, oxford = FALSE, ... ) ## S3 method for class 'factor' cc( object, conjunction = NULL, bracket = "'", ellipsis = 10, oxford = FALSE, ... ) ## S3 method for class 'data.frame' cc(object, conjunction = NULL, ellipsis = 10, oxford = FALSE, ...)
## Default S3 method: cc( object, conjunction = NULL, bracket = "", ellipsis = 10, oxford = FALSE, ... ) ## S3 method for class 'character' cc( object, conjunction = NULL, bracket = "'", ellipsis = 10, oxford = FALSE, ... ) ## S3 method for class 'factor' cc( object, conjunction = NULL, bracket = "'", ellipsis = 10, oxford = FALSE, ... ) ## S3 method for class 'data.frame' cc(object, conjunction = NULL, ellipsis = 10, oxford = FALSE, ...)
object |
The object with values to concatenate. |
conjunction |
A string of the conjunction to separate the last value by or NULL. |
bracket |
A string to bracket the values by. |
ellipsis |
A count of the total number of values required to use an ellipsis. |
oxford |
A flag indicating whether to use the Oxford comma (if conjunction). |
... |
Unused |
cc(c(1,1,1:2)) cc(100:1) cc(1:100, "and") cc(100:1, "or", bracket = "|", ellipsis = 5, oxford = TRUE) cc(mtcars)
cc(c(1,1,1:2)) cc(100:1) cc(1:100, "and") cc(100:1, "or", bracket = "|", ellipsis = 5, oxford = TRUE) cc(mtcars)
Customizable Number Aware String
cn( n, one = "there %r %n value%s", some = one, none = some, lots = some, nlots = 10 )
cn( n, one = "there %r %n value%s", some = one, none = some, lots = some, nlots = 10 )
n |
A count of the number. |
one |
The string to return if |
some |
The string to return if n is in |
none |
The string to return if |
lots |
The string to return if |
nlots |
A count of the number of values to consider to be lots |
A string of the updated message.
sprintf
-like typesThe following sprintf
-like types can be used in the custom messages:
n
the length of the object
s
's' if n != 1 otherwise ”
cn(0) cn(1) cn(4)
cn(0) cn(1) cn(4)
Produces a fully customizable object aware string with consecutive values separated by columns.
## Default S3 method: co( object, one = "%o has %n value%s: %c", some = one, none = gsub(": ", "", some), lots = some, nlots = 10, conjunction = NULL, bracket = "", ellipsis = nlots, oxford = FALSE, object_name = substitute(object), ... ) ## S3 method for class 'character' co( object, one = "%o has %n value%s: %c", some = one, none = gsub(": ", "", some), lots = some, nlots = 10, conjunction = NULL, bracket = "'", ellipsis = nlots, oxford = FALSE, object_name = substitute(object), ... ) ## S3 method for class 'factor' co( object, one = "%o has %n value%s: %c", some = one, none = gsub(": ", "", some), lots = some, nlots = 10, conjunction = NULL, bracket = "'", ellipsis = nlots, oxford = FALSE, object_name = substitute(object), ... ) ## S3 method for class 'data.frame' co( object, one = "%o has %n column%s\n%c", some = one, none = none, lots = some, nlots = 10, conjunction = NULL, ellipsis = nlots, oxford = FALSE, object_name = substitute(object), ... )
## Default S3 method: co( object, one = "%o has %n value%s: %c", some = one, none = gsub(": ", "", some), lots = some, nlots = 10, conjunction = NULL, bracket = "", ellipsis = nlots, oxford = FALSE, object_name = substitute(object), ... ) ## S3 method for class 'character' co( object, one = "%o has %n value%s: %c", some = one, none = gsub(": ", "", some), lots = some, nlots = 10, conjunction = NULL, bracket = "'", ellipsis = nlots, oxford = FALSE, object_name = substitute(object), ... ) ## S3 method for class 'factor' co( object, one = "%o has %n value%s: %c", some = one, none = gsub(": ", "", some), lots = some, nlots = 10, conjunction = NULL, bracket = "'", ellipsis = nlots, oxford = FALSE, object_name = substitute(object), ... ) ## S3 method for class 'data.frame' co( object, one = "%o has %n column%s\n%c", some = one, none = none, lots = some, nlots = 10, conjunction = NULL, ellipsis = nlots, oxford = FALSE, object_name = substitute(object), ... )
object |
The object of length |
one |
The string to return if |
some |
The string to return if n is in |
none |
The string to return if |
lots |
The string to return if |
nlots |
A count of the number of values to consider to be lots |
conjunction |
A string of the conjunction to separate the last value by or NULL. |
bracket |
A string to bracket the values by. |
ellipsis |
A count of the total number of values required to use an ellipsis. |
oxford |
A flag indicating whether to use the Oxford comma (if conjunction). |
object_name |
A string of the object name. |
... |
Unused. |
sprintf
-like typesThe following sprintf
-like types can be used in the custom messages:
c
the object as a comma separated list (produced by a cc
function)
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'
co(character()) x <- "fox" co(x) co(c(1,2,5)) co(1:10) co(datasets::mtcars)
co(character()) x <- "fox" co(x) co(c(1,2,5)) co(1:10) co(datasets::mtcars)
Wrappers with Conjunction and ” Brackets.
cc_and(object) cc_or(object) co_and( object, one = "%o has %n value%s: %c", object_name = substitute(object) ) co_or( object, one = "%o has %n value%s: %c", object_name = substitute(object) )
cc_and(object) cc_or(object) co_and( object, one = "%o has %n value%s: %c", object_name = substitute(object) ) co_or( object, one = "%o has %n value%s: %c", object_name = substitute(object) )
object |
The object with values to concatenate. |
one |
The string to return if |
object_name |
A string of the object name. |
cc_and
: Concatenation with Commas and And Conjunction
cc_or
: Concatenation with Commas and Or Conjunction
co_and
: Customizable Object Aware String and And Conjunction
co_or
: Customizable Object Aware String and Or Conjunction
cc_and(1:100) cc_or(100:1) co_and(1:100) co_or(100:1)
cc_and(1:100) cc_or(100:1) co_and(1:100) co_or(100:1)
Wrappers on paste
and paste0
to increase the readability of code.
p(..., sep = " ", collapse = NULL) p0(..., collapse = NULL)
p(..., sep = " ", collapse = NULL) p0(..., collapse = NULL)
... |
one or more R objects, to be converted to character vectors. |
sep |
a character string to separate the terms. Not
|
collapse |
an optional character string to separate the results. Not
|
A string of the pasted values.
p0
: Paste0
p("The", "red") p0("ard", "vark")
p("The", "red") p0("ard", "vark")