Skip to content

Commit 4a3dd71

Browse files
olivroyteunbrand
andauthored
Review error messages (#5557)
* Add full stops to error messages. * Remove self-ref * Replace `expect_snapshot_warning` and `expect_snapshot_error()` with `expect_snapshot()`. * Review and accept snapshots * error msg * style * typo * Revert "Replace `expect_snapshot_warning` and `expect_snapshot_error()` with `expect_snapshot()`." This reverts commit 3b7dcc7. * change * Update snapshots * Adjust failing tests * Apply suggestions from code review Co-authored-by: Teun van den Brand <[email protected]> * Apply suggestions from teunbrand --------- Co-authored-by: Teun van den Brand <[email protected]>
1 parent c00f875 commit 4a3dd71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+353
-345
lines changed

R/aes.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ alternative_aes_extract_usage <- function(x) {
425425
} else if (is_call(x, "$")) {
426426
as.character(x[[3]])
427427
} else {
428-
cli::cli_abort("Don't know how to get alternative usage for {.var {x}}")
428+
cli::cli_abort("Don't know how to get alternative usage for {.var {x}}.")
429429
}
430430
}
431431

R/annotation-custom.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ GeomCustomAnn <- ggproto("GeomCustomAnn", Geom,
7171
draw_panel = function(data, panel_params, coord, grob, xmin, xmax,
7272
ymin, ymax) {
7373
if (!inherits(coord, "CoordCartesian")) {
74-
cli::cli_abort("{.fn annotation_custom} only works with {.fn coord_cartesian}")
74+
cli::cli_abort("{.fn annotation_custom} only works with {.fn coord_cartesian}.")
7575
}
7676
corners <- data_frame0(
7777
x = c(xmin, xmax),

R/annotation-map.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ annotation_map <- function(map, ...) {
6363
if (!is.null(map$long)) map$x <- map$long
6464
if (!is.null(map$region)) map$id <- map$region
6565
if (!all(c("x", "y", "id") %in% names(map))) {
66-
cli::cli_abort("{.arg map} must have the columns {.col x}, {.col y}, and {.col id}")
66+
cli::cli_abort("{.arg map} must have the columns {.col x}, {.col y}, and {.col id}.")
6767
}
6868

6969
layer(

R/annotation-raster.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ GeomRasterAnn <- ggproto("GeomRasterAnn", Geom,
7474
draw_panel = function(data, panel_params, coord, raster, xmin, xmax,
7575
ymin, ymax, interpolate = FALSE) {
7676
if (!inherits(coord, "CoordCartesian")) {
77-
cli::cli_abort("{.fn annotation_raster} only works with {.fn coord_cartesian}")
77+
cli::cli_abort("{.fn annotation_raster} only works with {.fn coord_cartesian}.")
7878
}
7979
corners <- data_frame0(
8080
x = c(xmin, xmax),

R/annotation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#'
1414
#' @section Unsupported geoms:
1515
#' Due to their special nature, reference line geoms [geom_abline()],
16-
#' [geom_hline()], and [geom_vline()] can't be used with [annotate()].
16+
#' [geom_hline()], and [geom_vline()] can't be used with `annotate()`.
1717
#' You can use these geoms directly for annotations.
1818
#' @param geom name of geom to use for annotation
1919
#' @param x,y,xmin,ymin,xmax,ymax,xend,yend positioning aesthetics -

R/autolayer.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ autolayer <- function(object, ...) {
1515

1616
#' @export
1717
autolayer.default <- function(object, ...) {
18-
cli::cli_abort("No autolayer method available for {.cls {class(object)[1]}} objects")
18+
cli::cli_abort("No autolayer method available for {.cls {class(object)[1]}} objects.")
1919
}

R/autoplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ autoplot <- function(object, ...) {
1717
autoplot.default <- function(object, ...) {
1818
cli::cli_abort(c(
1919
"Objects of class {.cls {class(object)[[1]]}} are not supported by autoplot.",
20-
"i" = "have you loaded the required package?"
20+
"i" = "Have you loaded the required package?"
2121
))
2222
}
2323

R/axis-secondary.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ set_sec_axis <- function(sec.axis, scale) {
123123
if (!is.waive(sec.axis)) {
124124
if (is.formula(sec.axis)) sec.axis <- sec_axis(sec.axis)
125125
if (!is.sec_axis(sec.axis)) {
126-
cli::cli_abort("Secondary axes must be specified using {.fn sec_axis}")
126+
cli::cli_abort("Secondary axes must be specified using {.fn sec_axis}.")
127127
}
128128
scale$secondary.axis <- sec.axis
129129
}
@@ -165,7 +165,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
165165
return()
166166
}
167167
if (!is.function(self$trans)) {
168-
cli::cli_abort("Transformation for secondary axes must be a function")
168+
cli::cli_abort("Transformation for secondary axes must be a function.")
169169
}
170170
if (is.derived(self$name) && !is.waive(scale$name)) self$name <- scale$name
171171
if (is.derived(self$breaks)) self$breaks <- scale$breaks
@@ -194,7 +194,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
194194

195195
# Test for monotonicity
196196
if (!is_unique(sign(diff(full_range))))
197-
cli::cli_abort("Transformation for secondary axes must be monotonic")
197+
cli::cli_abort("Transformation for secondary axes must be monotonic.")
198198
},
199199

200200
break_info = function(self, range, scale) {

R/bin.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ bin_breaks <- function(breaks, closed = c("right", "left")) {
5151
bin_breaks_width <- function(x_range, width = NULL, center = NULL,
5252
boundary = NULL, closed = c("right", "left")) {
5353
if (length(x_range) != 2) {
54-
cli::cli_abort("{.arg x_range} must have two elements")
54+
cli::cli_abort("{.arg x_range} must have two elements.")
5555
}
5656

57-
check_number_decimal(width)
58-
if (width <= 0) {
59-
cli::cli_abort("{.arg binwidth} must be positive")
60-
}
57+
# binwidth seems to be the argument name supplied to width. (stat-bin and stat-bindot)
58+
check_number_decimal(width, min = 0, allow_infinite = FALSE, arg = "binwidth")
6159

6260
if (!is.null(boundary) && !is.null(center)) {
6361
cli::cli_abort("Only one of {.arg boundary} and {.arg center} may be specified.")
@@ -105,7 +103,7 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
105103
bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
106104
boundary = NULL, closed = c("right", "left")) {
107105
if (length(x_range) != 2) {
108-
cli::cli_abort("{.arg x_range} must have two elements")
106+
cli::cli_abort("{.arg x_range} must have two elements.")
109107
}
110108

111109
check_number_whole(bins, min = 1)

R/compat-plyr.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ unrowname <- function(x) {
1919
} else if (is.matrix(x)) {
2020
dimnames(x)[1] <- list(NULL)
2121
} else {
22-
cli::cli_abort("Can only remove rownames from {.cls data.frame} and {.cls matrix} objects")
22+
cli::cli_abort("Can only remove rownames from {.cls data.frame} and {.cls matrix} objects.")
2323
}
2424
x
2525
}
@@ -239,7 +239,7 @@ as.quoted <- function(x, env = parent.frame()) {
239239
} else if (is.call(x)) {
240240
as.list(x)[-1]
241241
} else {
242-
cli::cli_abort("Must be a character vector, call, or formula")
242+
cli::cli_abort("Must be a character vector, call, or formula.")
243243
}
244244
attributes(x) <- list(env = env, class = 'quoted')
245245
x

R/coord-.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,27 @@ Coord <- ggproto("Coord",
6666
render_fg = function(panel_params, theme) element_render(theme, "panel.border"),
6767

6868
render_bg = function(self, panel_params, theme) {
69-
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_bg} method")
69+
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_bg} method.")
7070
},
7171

7272
render_axis_h = function(self, panel_params, theme) {
73-
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_axis_h} method")
73+
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_axis_h} method.")
7474
},
7575

7676
render_axis_v = function(self, panel_params, theme) {
77-
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_axis_v} method")
77+
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_axis_v} method.")
7878
},
7979

8080
# transform range given in transformed coordinates
8181
# back into range in given in (possibly scale-transformed)
8282
# data coordinates
8383
backtransform_range = function(self, panel_params) {
84-
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn backtransform_range} method")
84+
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn backtransform_range} method.")
8585
},
8686

8787
# return range stored in panel_params
8888
range = function(self, panel_params) {
89-
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn range} method")
89+
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn range} method.")
9090
},
9191

9292
setup_panel_params = function(scale_x, scale_y, params = list()) {

R/coord-sf.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
127127
}
128128

129129
if (length(x_labels) != length(x_breaks)) {
130-
cli::cli_abort("Breaks and labels along x direction are different lengths")
130+
cli::cli_abort("{.arg breaks} and {.arg labels} along {.code x} direction have different lengths.")
131131
}
132132
graticule$degree_label[graticule$type == "E"] <- x_labels
133133

@@ -152,7 +152,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
152152
}
153153

154154
if (length(y_labels) != length(y_breaks)) {
155-
cli::cli_abort("Breaks and labels along y direction are different lengths")
155+
cli::cli_abort("{.arg breaks} and {.arg labels} along {.code y} direction have different lengths.")
156156
}
157157
graticule$degree_label[graticule$type == "N"] <- y_labels
158158

@@ -203,7 +203,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
203203
if (self$lims_method != "geometry_bbox") {
204204
cli::cli_warn(c(
205205
"Projection of {.field x} or {.field y} limits failed in {.fn coord_sf}.",
206-
"i" = "Consider setting {.code lims_method = \"geometry_bbox\"} or {.code default_crs = NULL}."
206+
"i" = "Consider setting {.code lims_method = {.val geometry_bbox}} or {.code default_crs = NULL}."
207207
))
208208
}
209209
coord_bbox <- self$params$bbox
@@ -409,7 +409,7 @@ sf_rescale01 <- function(x, x_range, y_range) {
409409
calc_limits_bbox <- function(method, xlim, ylim, crs, default_crs) {
410410
if (any(!is.finite(c(xlim, ylim))) && method != "geometry_bbox") {
411411
cli::cli_abort(c(
412-
"Scale limits cannot be mapped onto spatial coordinates in {.fn coord_sf}",
412+
"Scale limits cannot be mapped onto spatial coordinates in {.fn coord_sf}.",
413413
"i" = "Consider setting {.code lims_method = \"geometry_bbox\"} or {.code default_crs = NULL}."
414414
))
415415
}
@@ -542,14 +542,12 @@ coord_sf <- function(xlim = NULL, ylim = NULL, expand = TRUE,
542542
label_axes <- parse_axes_labeling(label_axes)
543543
} else if (!is.list(label_axes)) {
544544
cli::cli_abort("Panel labeling format not recognized.")
545-
label_axes <- list(left = "N", bottom = "E")
546545
}
547546

548547
if (is.character(label_graticule)) {
549548
label_graticule <- unlist(strsplit(label_graticule, ""))
550549
} else {
551550
cli::cli_abort("Graticule labeling format not recognized.")
552-
label_graticule <- ""
553551
}
554552

555553
# switch limit method to "orthogonal" if not specified and default_crs indicates projected coords

R/facet-.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ Facet <- ggproto("Facet", NULL,
8383
params = list(),
8484

8585
compute_layout = function(data, params) {
86-
cli::cli_abort("Not implemented")
86+
cli::cli_abort("Not implemented.")
8787
},
8888
map_data = function(data, layout, params) {
89-
cli::cli_abort("Not implemented")
89+
cli::cli_abort("Not implemented.")
9090
},
9191
init_scales = function(layout, x_scale = NULL, y_scale = NULL, params) {
9292
scales <- list()
@@ -132,7 +132,7 @@ Facet <- ggproto("Facet", NULL,
132132
rep(list(zeroGrob()), vec_unique_count(layout$PANEL))
133133
},
134134
draw_panels = function(panels, layout, x_scales, y_scales, ranges, coord, data, theme, params) {
135-
cli::cli_abort("Not implemented")
135+
cli::cli_abort("Not implemented.")
136136
},
137137
draw_labels = function(panels, layout, x_scales, y_scales, ranges, coord, data, theme, labels, params) {
138138
panel_dim <- find_panel(panels)
@@ -323,13 +323,13 @@ as_facets_list <- function(x) {
323323

324324
validate_facets <- function(x) {
325325
if (inherits(x, "uneval")) {
326-
cli::cli_abort("Please use {.fn vars} to supply facet variables")
326+
cli::cli_abort("Please use {.fn vars} to supply facet variables.")
327327
}
328328
# Native pipe have higher precedence than + so any type of gg object can be
329329
# expected here, not just ggplot
330330
if (inherits(x, "gg")) {
331331
cli::cli_abort(c(
332-
"Please use {.fn vars} to supply facet variables",
332+
"Please use {.fn vars} to supply facet variables.",
333333
"i" = "Did you use {.code %>%} or {.code |>} instead of {.code +}?"
334334
))
335335
}
@@ -500,7 +500,7 @@ check_layout <- function(x) {
500500
return()
501501
}
502502

503-
cli::cli_abort("Facet layout has a bad format. It must contain columns {.col PANEL}, {.col SCALE_X}, and {.col SCALE_Y}")
503+
cli::cli_abort("Facet layout has a bad format. It must contain columns {.col PANEL}, {.col SCALE_X}, and {.col SCALE_Y}.")
504504
}
505505

506506
check_facet_vars <- function(..., name) {
@@ -509,8 +509,8 @@ check_facet_vars <- function(..., name) {
509509
problems <- intersect(vars_names, reserved_names)
510510
if (length(problems) != 0) {
511511
cli::cli_abort(c(
512-
"{.val {problems}} {?is/are} not {?an/} allowed name{?/s} for faceting variables",
513-
"i" = "Change the name of your data columns to not be {.or {.str {reserved_names}}}"
512+
"{.val {problems}} {?is/are} not {?an/} allowed name{?/s} for faceting variables.",
513+
"i" = "Change the name of your data columns to not be {.or {.str {reserved_names}}}."
514514
), call = call2(name))
515515
}
516516
}
@@ -631,7 +631,7 @@ combine_vars <- function(data, env = emptyenv(), vars = NULL, drop = TRUE) {
631631
}
632632

633633
if (empty(base)) {
634-
cli::cli_abort("Faceting variables must have at least one value")
634+
cli::cli_abort("Faceting variables must have at least one value.")
635635
}
636636

637637
base

R/facet-grid-.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ facet_grid <- function(rows = NULL, cols = NULL, scales = "fixed",
137137
y = any(space %in% c("free_y", "free"))
138138
)
139139

140-
if (!is.null(switch) && !switch %in% c("both", "x", "y")) {
141-
cli::cli_abort("{.arg switch} must be either {.val both}, {.val x}, or {.val y}")
140+
if (!is.null(switch)) {
141+
arg_match0(switch, c("both", "x", "y"))
142142
}
143143

144144
facets_list <- grid_as_facets_list(rows, cols)
@@ -159,7 +159,7 @@ grid_as_facets_list <- function(rows, cols) {
159159
is_rows_vars <- is.null(rows) || is_quosures(rows)
160160
if (!is_rows_vars) {
161161
if (!is.null(cols)) {
162-
msg <- "{.arg rows} must be {.val NULL} or a {.fn vars} list if {.arg cols} is a {.fn vars} list"
162+
msg <- "{.arg rows} must be {.code NULL} or a {.fn vars} list if {.arg cols} is a {.fn vars} list."
163163
# Native pipe have higher precedence than + so any type of gg object can be
164164
# expected here, not just ggplot
165165
if (inherits(rows, "gg")) {
@@ -173,7 +173,7 @@ grid_as_facets_list <- function(rows, cols) {
173173
# For backward-compatibility
174174
facets_list <- as_facets_list(rows)
175175
if (length(facets_list) > 2L) {
176-
cli::cli_abort("A grid facet specification can't have more than two dimensions")
176+
cli::cli_abort("A grid facet specification can't have more than two dimensions.")
177177
}
178178
# Fill with empty quosures
179179
facets <- list(rows = quos(), cols = quos())
@@ -206,7 +206,7 @@ FacetGrid <- ggproto("FacetGrid", Facet,
206206
dups <- intersect(names(rows), names(cols))
207207
if (length(dups) > 0) {
208208
cli::cli_abort(c(
209-
"Faceting variables can only appear in {.arg rows} or {.arg cols}, not both.\n",
209+
"Faceting variables can only appear in {.arg rows} or {.arg cols}, not both.",
210210
"i" = "Duplicated variables: {.val {dups}}"
211211
), call = call2(snake_class(self)))
212212
}
@@ -303,7 +303,7 @@ FacetGrid <- ggproto("FacetGrid", Facet,
303303
},
304304
draw_panels = function(panels, layout, x_scales, y_scales, ranges, coord, data, theme, params) {
305305
if ((params$free$x || params$free$y) && !coord$is_free()) {
306-
cli::cli_abort("{.fn {snake_class(coord)}} doesn't support free scales")
306+
cli::cli_abort("{.fn {snake_class(coord)}} doesn't support free scales.")
307307
}
308308

309309
cols <- which(layout$ROW == 1)
@@ -321,7 +321,7 @@ FacetGrid <- ggproto("FacetGrid", Facet,
321321

322322
aspect_ratio <- theme$aspect.ratio
323323
if (!is.null(aspect_ratio) && (params$space_free$x || params$space_free$y)) {
324-
cli::cli_abort("Free scales cannot be mixed with a fixed aspect ratio")
324+
cli::cli_abort("Free scales cannot be mixed with a fixed aspect ratio.")
325325
}
326326
if (is.null(aspect_ratio) && !params$free$x && !params$free$y) {
327327
aspect_ratio <- coord$aspect(ranges[[1]])

R/facet-wrap.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ FacetWrap <- ggproto("FacetWrap", Facet,
217217
},
218218
draw_panels = function(self, panels, layout, x_scales, y_scales, ranges, coord, data, theme, params) {
219219
if ((params$free$x || params$free$y) && !coord$is_free()) {
220-
cli::cli_abort("{.fn {snake_class(self)}} can't use free scales with {.fn {snake_class(coord)}}")
220+
cli::cli_abort("{.fn {snake_class(self)}} can't use free scales with {.fn {snake_class(coord)}}.")
221221
}
222222

223223
if (inherits(coord, "CoordFlip")) {
@@ -470,8 +470,8 @@ wrap_dims <- function(n, nrow = NULL, ncol = NULL) {
470470
}
471471
if (nrow * ncol < n) {
472472
cli::cli_abort(c(
473-
"Need {n} panels, but together {.arg nrow} and {.arg ncol} only provide {nrow * ncol}",
474-
i = "Please increase {.arg ncol} and/or {.arg nrow}"
473+
"Need {n} panel{?s}, but together {.arg nrow} and {.arg ncol} only provide {nrow * ncol}.",
474+
i = "Please increase {.arg ncol} and/or {.arg nrow}."
475475
))
476476
}
477477

R/fortify.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ validate_as_data_frame <- function(data) {
7878
fortify.default <- function(model, data, ...) {
7979
msg0 <- paste0(
8080
"{{.arg data}} must be a {{.cls data.frame}}, ",
81-
"or an object coercible by {{.code fortify()}}, or a valid ",
82-
"{{.cls data.frame}}-like object coercible by {{.code as.data.frame()}}"
81+
"or an object coercible by {{.fn fortify}}, or a valid ",
82+
"{{.cls data.frame}}-like object coercible by {{.fn as.data.frame}}"
8383
)
8484
if (inherits(model, "uneval")) {
8585
msg <- c(

R/geom-.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ check_aesthetics <- function(x, n) {
239239
}
240240

241241
cli::cli_abort(c(
242-
"Aesthetics must be either length 1 or the same as the data ({n})",
243-
"x" = "Fix the following mappings: {.col {names(which(!good))}}"
242+
"Aesthetics must be either length 1 or the same as the data ({n}).",
243+
"x" = "Fix the following mappings: {.col {names(which(!good))}}."
244244
))
245245
}
246246

R/geom-boxplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
230230
# this may occur when using geom_boxplot(stat = "identity")
231231
if (nrow(data) != 1) {
232232
cli::cli_abort(c(
233-
"Can only draw one boxplot per group",
233+
"Can only draw one boxplot per group.",
234234
"i"= "Did you forget {.code aes(group = ...)}?"
235235
))
236236
}

0 commit comments

Comments
 (0)