Skip to content

Commit

Permalink
Replace paste0 with \\ in messages
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Jan 23, 2024
1 parent 89ffc1c commit fb1e01f
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 95 deletions.
24 changes: 12 additions & 12 deletions R/borrowed_ggplot2.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ check_labeller <- function(labeller) {
labeller <- function(labels) {
Map(old_labeller, names(labels), labels)
}
cli::cli_warn(c(paste0(
"The {.arg labeller} API has been updated. Labellers taking ",
"{.arg variable} and {.arg value} arguments are now deprecated.",
), i = "See labellers documentation."))
cli::cli_warn(c(
"The {.arg labeller} API has been updated. Labellers taking \\
{.arg variable} and {.arg value} arguments are now deprecated.",
), i = "See labellers documentation.")
}
labeller
}
Expand All @@ -120,10 +120,10 @@ unrowname <- function(x) {
} else if (is.matrix(x)) {
dimnames(x)[1] <- list(NULL)
} else {
cli::cli_abort(paste0(
"Can only remove rownames from {.cls data.frame} and ",
"{.cls matrix} objects."
))
cli::cli_abort(
"Can only remove rownames from {.cls data.frame} and \\
{.cls matrix} objects."
)
}
x
}
Expand Down Expand Up @@ -457,10 +457,10 @@ justify_grobs <- function(
lapply(grobs, justify_grobs, x, y, hjust, vjust, int_angle, debug)
)
} else {
cli::cli_abort(paste0(
"{.arg grobs} must be an individual {.cls grob} or list of {.cls grob}",
" objects."
))
cli::cli_abort(
"{.arg grobs} must be an individual {.cls grob} or list of \\
{.cls grob} objects."
)
}
}
if (inherits(grobs, "zeroGrob")) {
Expand Down
8 changes: 4 additions & 4 deletions R/conveniences.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ weave_factors <- function(..., drop = TRUE, sep = ".", replaceNA = TRUE) {
}
lengths <- lengths(args)
if (!all(lengths %in% c(1L, max(lengths)))) {
cli::cli_abort(paste0(
"All inputs to {.fn weave_factors} should have the same length, ",
"or length 1."
))
cli::cli_abort(
"All inputs to {.fn weave_factors} should have the same length, \\
or length 1."
)
}
if (replaceNA) {
args <- lapply(args, function(x) {
Expand Down
4 changes: 2 additions & 2 deletions R/facet_grid2.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ FacetGrid2 <- ggproto(
dups <- intersect(names(rows), names(cols))
if (length(dups) > 0) {
cli::cli_abort(c(
paste0("Facetting variables can only appear in {.arg rows} or
{.arg cols}, not both."),
"Facetting variables can only appear in {.arg rows} or \\
{.arg cols}, not both.",
i = "Duplicated variables: {.val dups}"
))
}
Expand Down
12 changes: 6 additions & 6 deletions R/facet_nested.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ facet_nested <- function(
nest_line <- element_blank()
}
if (!inherits(nest_line, c("element_line", "element_blank"))) {
cli::cli_abort(paste0(
"The {.arg nest_line} argument must be {.cls element_blank} or inherit ",
"from {.cls element_line}."
))
cli::cli_abort(
"The {.arg nest_line} argument must be {.cls element_blank} or inherit \\
from {.cls element_line}."
)
}

params <- list(
Expand Down Expand Up @@ -206,8 +206,8 @@ FacetNested <- ggproto(
names(missing_vars) <- rep("x", length(data))

cli::cli_abort(c(paste0(
"At least one layer must contain all faceting variables: ",
"{.var {names(vars)}}"
"At least one layer must contain all faceting variables: \\
{.var {names(vars)}}"
), missing_vars))
}
base <- unique0(vec_rbind(!!!values[has_all]))
Expand Down
8 changes: 4 additions & 4 deletions R/facet_nested_wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ facet_nested_wrap <- function(
nest_line <- element_blank()
}
if (!inherits(nest_line, c("element_line", "element_blank"))) {
cli::cli_abort(paste0(
"The {.arg nest_line} argument must be {.cls element_blank} or inherit ",
"from {.cls element_line}."
))
cli::cli_abort(
"The {.arg nest_line} argument must be {.cls element_blank} or inherit \\
from {.cls element_line}."
)
}
params <- list(
nest_line = nest_line,
Expand Down
4 changes: 2 additions & 2 deletions R/facetted_pos_scales.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ validate_facetted_scale <- function(x, aes = "x") {
# Double check for appropriate scales
check <- check_facetted_scale(rhs, aes = aes, allow_null = FALSE)
if (!check) {
cli::cli_abort(paste0(
cli::cli_abort(
"The right-hand side of formula does not result in an appropriate scale."
))
)
}

return(
Expand Down
7 changes: 3 additions & 4 deletions R/geom_box.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ GeomBox <- ggproto(
"every row?"
))
}
cli::cli_warn(c(paste0(
"Could not resolve the position of every {.arg {missing}} ",
"aesthetic{?s}."
), tip))
cli::cli_warn(c(
"Could not resolve the position of every {.arg {missing}} \\
aesthetic{?s}.", tip))
}

data[c("xmin", "xmax", "ymin", "ymax")] <- list(x$min, x$max, y$min, y$max)
Expand Down
4 changes: 2 additions & 2 deletions R/geom_rectrug.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ GeomRectMargin <- ggplot2::ggproto(
) {

if (!inherits(length, "unit")) {
cli::cli_abort(paste0(
cli::cli_abort(
"The {.arg length} argument must be a {.cls unit} object."
))
)
}
rugs <- list()
coords <- coord$transform(data, panel_params)
Expand Down
8 changes: 4 additions & 4 deletions R/geom_text_aimed.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ geom_text_aimed <- function(
) {
if (!missing(nudge_x) || !missing(nudge_y)) {
if (!missing(position)) {
cli::cli_abort(paste0(
"Specify either {.arg position} or {.arg nudge_x}/{.arg nudge_y}, ",
"not both."
))
cli::cli_abort(
"Specify either {.arg position} or {.arg nudge_x}/{.arg nudge_y}, \\
not both."
)
}
position <- position_nudge(nudge_x, nudge_y)
}
Expand Down
8 changes: 4 additions & 4 deletions R/guide_axis_manual.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ guide_train.axis_manual <- function(guide, scale, aesthetic = NULL) {
# Warn when a transformation tries to auto-label grid units
if (is.unit(breaks) && inherits(guide$labels, "waiver")) {
if (!scale$is_discrete() && transformation$name != "identity") {
cli::cli_warn(c(paste0(
"Setting {.cls unit} objects for breaks might not work elegantly with ",
"the default scale labelling."
), i = "You can set the {.arg labels} argument."))
cli::cli_warn(c(
"Setting {.cls unit} objects for breaks might not work elegantly with \\
the default scale labelling.",
i = "You can set the {.arg labels} argument."))
}
}

Expand Down
16 changes: 8 additions & 8 deletions R/guide_axis_truncated.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,10 @@ truncate_guide <- function(guide, scale, aesthetic) {
guide$key[[aesthetic]], guide$trunc_upper, scale, "upper"
)
if (!(length(guide$trunc_lower) == length(guide$trunc_upper))) {
cli::cli_abort(paste0(
"Axis truncation must have an equal number of upper and lower ",
"truncation points."
))
cli::cli_abort(
"Axis truncation must have an equal number of upper and lower \\
truncation points."
)
}
trunc <- data_frame0(
"start" = trunc_lower,
Expand Down Expand Up @@ -356,10 +356,10 @@ check_trunc_arg <- function(lower, upper) {
if (!is.function(lower) && !is.function(upper)) {
lens <- c(length(lower), length(upper))
if (lens[1] != lens[2] & !any(lens == 0)) {
cli::cli_abort(paste0(
"Axis truncation must have an equal number of upper and lower ",
"truncation points."
))
cli::cli_abort(
"Axis truncation must have an equal number of upper and lower \\
truncation points."
)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions R/guide_stringlegend.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ guide_gengrob.stringlegend <- function(guide, theme) {
nbreak <- nrow(guide$key)
if (!is.null(guide$nrow) && !is.null(guide$ncol) &&
guide$nrow * guide$ncol < nbreak) {
cli::cli_abort(paste0(
cli::cli_abort(
"{.arg nrow} * {.arg ncol} needs to be larger than the number of breaks."
))
)
}

if (is.null(guide$nrow) && is.null(guide$ncol)) {
Expand Down
8 changes: 4 additions & 4 deletions R/scale_facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ scale_facet <- function(expr, aes, ..., type = "continuous") {
candidates <- paste("scale", aes, type, sep = "_")

if (type == "facet") {
cli::cli_abort(paste0(
"Cannot circularly define {.fun {candidates[1]}} as template for ",
"{.fun {candidates[1]}}."
))
cli::cli_abort(
"Cannot circularly define {.fun {candidates[1]}} as template for \\
{.fun {candidates[1]}}."
)
}

for (candi in candidates) {
Expand Down
24 changes: 12 additions & 12 deletions R/scale_listed.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
scale_listed <- function(scalelist, replaces = NULL) {
# Check replaces validity
if (length(scalelist) != length(replaces)) {
cli::cli_abort(paste0(
"The {.arg replaces} argument must be parallel to and of the same ",
"length as the {.arg scalelist} argument."
))
cli::cli_abort(
"The {.arg replaces} argument must be parallel to and of the same \\
length as the {.arg scalelist} argument."
)
}
replaces <- standardise_aes_names(replaces)
if (!(all(replaces %in% .all_aesthetics))) {
Expand All @@ -75,10 +75,10 @@ scale_listed <- function(scalelist, replaces = NULL) {
inherits(scale, "gg"))
}, logical(1))
if (!all(check)) {
cli::cli_abort(paste0(
"The {.arg scalelist} argument must have valid {.cls Scale} objects as",
"list-elements."
))
cli::cli_abort(
"The {.arg scalelist} argument must have valid {.cls Scale} objects as \\
list-elements."
)
}

# Check scale aesthetics
Expand All @@ -91,10 +91,10 @@ scale_listed <- function(scalelist, replaces = NULL) {
aesthetics <- unlist(aesthetics)

if (length(aesthetics) != length(replaces)) {
cli::cli_abort(paste0(
"Every scale in the {.arg scalelist} argument must have set ",
"valid aesthetics."
))
cli::cli_abort(
"Every scale in the {.arg scalelist} argument must have set \\
valid aesthetics."
)
}

# Interpret guides
Expand Down
16 changes: 8 additions & 8 deletions R/scale_manual.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ scale_position_manual <- function(

pal <- function(limits) {
if (length(limits) > length(values)) {
cli::cli_abort(paste0(
"Insufficient values in manual scale. {length(limits)} needed ",
"but {length(values)} provided."
))
cli::cli_abort(
"Insufficient values in manual scale. {length(limits)} needed \\
but {length(values)} provided."
)
}
values[seq_along(limits)]
}
Expand All @@ -132,10 +132,10 @@ scale_position_manual <- function(
}

if (!is.null(c_limits) && (!is.numeric(c_limits) || length(c_limits) != 2)) {
cli::cli_abort(paste0(
"The {.arg c_limits} argument must either be {.code NULL} or a ",
"{.cls numeric} vector of length 2."
))
cli::cli_abort(
"The {.arg c_limits} argument must either be {.code NULL} or a \\
{.cls numeric} vector of length 2."
)
}

sc <- discrete_scale(
Expand Down
24 changes: 12 additions & 12 deletions R/stat_theodensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ stat_theodensity <- function(
inherit.aes = TRUE
) {
if (!exists(paste0("d", distri), mode = "function")) {
cli::cli_abort(paste0(
"The {.arg distri} argument must have a valid density function called",
"{.fn d{distri}}."
))
cli::cli_abort(
"The {.arg distri} argument must have a valid density function called \\
{.fn d{distri}}."
)
}
if (distri %in% c("multinom", "hyper", "wilcox", "signrank")) {
cli::cli_abort(
Expand Down Expand Up @@ -196,10 +196,10 @@ StatTheoDensity <- ggproto(
dtype <- class_distri(params$distri)
if (dtype == "discrete") {
if (sum(abs(data$x %% 1)) > 0) {
cli::cli_abort(paste0(
"A discrete '{params$distri}' distribution cannot be fitted ",
"to continuous data."
))
cli::cli_abort(
"A discrete '{params$distri}' distribution cannot be fitted \\
to continuous data."
)
}
}
params <- c(params, distri_type = dtype)
Expand Down Expand Up @@ -261,9 +261,9 @@ class_distri <- function(distri) {
} else if (is.numeric(routput)) {
return("continuous")
} else {
cli::cli_abort(paste0(
"{.fn stat_theodensity} failed to determine if the '{distri}' ",
"distribution is discrete or continuous."
))
cli::cli_abort(
"{.fn stat_theodensity} failed to determine if the '{distri}' \\
distribution is discrete or continuous."
)
}
}
8 changes: 4 additions & 4 deletions R/strip_themed.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ validate_element_list <- function(elem, prototype = "element_text") {
is_proto <- vapply(elem, inherits, logical(1), c(prototype, "element_blank"))
is_null <- vapply(elem, is.null, logical(1))
if (any(!(is_proto | is_null))) {
cli::cli_abort(paste0(
"The {.arg {argname}} argument should be a list of {.cls {prototype}} ",
"objects."
))
cli::cli_abort(
"The {.arg {argname}} argument should be a list of {.cls {prototype}} \\
objects."
)
}
return(elem)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/scale_listed.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# scale_listed throws error when non-scales are supplied as scalelist

The `scalelist` argument must have valid <Scale> objects aslist-elements.
The `scalelist` argument must have valid <Scale> objects as list-elements.

# scale_listed throws error when multiple aesthetics are supplied in a scale

Expand Down

0 comments on commit fb1e01f

Please sign in to comment.