Skip to content

Commit 5ecc4a2

Browse files
committed
fallbacks
1 parent c464aa7 commit 5ecc4a2

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

R/position-connection.R

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
position_connect <- function(connection = "hv") {
44
ggproto(
55
NULL, PositionConnect,
6-
connection = validate_connection(connection)
6+
connection = connection
77
)
88
}
99

@@ -12,19 +12,26 @@ PositionConnect <- ggproto(
1212
connection = "hv",
1313
setup_params = function(self, data) {
1414
flipped_aes <- has_flipped_aes(data, ambiguous = TRUE)
15-
connection <- self$connection
15+
connection <- validate_connection(
16+
self$connection,
17+
call = expr(position_connect())
18+
)
1619
if (isTRUE(flipped_aes)) {
1720
connection <- connection[, 2:1]
1821
}
1922
list(flipped_aes = flipped_aes, connection = connection)
2023
},
2124
compute_panel = function(data, params, scales) {
25+
if (is.null(params$connection)) {
26+
return(data)
27+
}
2228
data <- flip_data(data, params$flipped_aes)
2329
data <- dapply(data, "group", build_connection, connection = params$connection)
2430
flip_data(data, params$flipped_aes)
2531
}
2632
)
2733

34+
# Ensures connection is a 2D numerical matrix with 2 columns
2835
validate_connection <- function(connection, call = caller_env()) {
2936
if (is.character(connection)) {
3037
check_string(connection)
@@ -41,14 +48,24 @@ validate_connection <- function(connection, call = caller_env()) {
4148
!identical(dim(connection)[2], 2L)) {
4249
extra <- ""
4350
if (!is.null(dim(connection)[2])) {
44-
extra <- " with {dim(connection)[2]} columns"
51+
extra <- paste0(" with ", dim(connection)[2], " columns")
4552
}
4653
cli::cli_abort(
4754
paste0("{.arg connection} must be a numeric {.cls matrix} with 2 columns, \\
48-
not {.obj_type_friendly {connection}}", extra, "."),
55+
not {.obj_type_friendly {connection}}{extra}."),
56+
call = call
57+
)
58+
}
59+
if (any(!is.finite(connection))) {
60+
cli::cli_abort(
61+
"{.arg connection} cannot contain missing or other non-finite values.",
4962
call = call
5063
)
5164
}
65+
66+
if (nrow(connection) < 1) {
67+
return(NULL)
68+
}
5269
connection
5370
}
5471

0 commit comments

Comments
 (0)