Skip to content

Commit 76b9a55

Browse files
yutannihilationthomasp85
authored andcommitted
Fix Travis failures on r-devel (tidyverse#3163)
* Wrap multiple logicals with isTRUE(), isFALSE(), all() or any() to ensure the errors related to R_CHECK_LENGTH_1_LOGIC2 * Backport isFALSE()
1 parent 8081b56 commit 76b9a55

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

R/backports.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ if (getRversion() < 3.3) {
1414
} else {
1515
backport_unit_methods <- function() {}
1616
}
17+
18+
# isFALSE() is available on R (>=3.5)
19+
if (getRversion() < 3.5) {
20+
isFALSE <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && !x
21+
}

R/guide-colorbar.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ guide_geom.colorbar <- function(guide, layers, default_mapping) {
244244
guide_layers <- plyr::llply(layers, function(layer) {
245245
matched <- matched_aes(layer, guide, default_mapping)
246246

247-
if (length(matched) && ((is.na(layer$show.legend) || layer$show.legend))) {
247+
if (length(matched) > 0 && (isTRUE(is.na(layer$show.legend)) || isTRUE(layer$show.legend))) {
248248
layer
249249
} else {
250250
# This layer does not use this guide

R/guide-legend.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ guide_geom.legend <- function(guide, layers, default_mapping) {
254254
include <- is.na(layer$show.legend[matched]) ||
255255
layer$show.legend[matched]
256256
} else {
257-
include <- is.na(layer$show.legend) || layer$show.legend
257+
include <- isTRUE(is.na(layer$show.legend)) || isTRUE(layer$show.legend)
258258
}
259259

260260
if (include) {
@@ -270,7 +270,7 @@ guide_geom.legend <- function(guide, layers, default_mapping) {
270270
}
271271
} else {
272272
# This layer does not contribute to the legend
273-
if (is.na(layer$show.legend) || !layer$show.legend) {
273+
if (isTRUE(is.na(layer$show.legend)) || !isTRUE(layer$show.legend)) {
274274
# Default is to exclude it
275275
return(NULL)
276276
} else {

R/guides-.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ guides_train <- function(scales, theme, guides, labels) {
173173
# this should be changed to testing guide == "none"
174174
# scale$legend is backward compatibility
175175
# if guides(XXX=FALSE), then scale_ZZZ(guides=XXX) is discarded.
176-
if (guide == "none" || (is.logical(guide) && !guide)) next
176+
if (identical(guide, "none") || isFALSE(guide)) next
177177

178178
# check the validity of guide.
179179
# if guide is character, then find the guide object
180180
guide <- validate_guide(guide)
181181

182182
# check the consistency of the guide and scale.
183-
if (guide$available_aes != "any" && !scale$aesthetics %in% guide$available_aes)
183+
if (!identical(guide$available_aes, "any") && !any(scale$aesthetics %in% guide$available_aes))
184184
stop("Guide '", guide$name, "' cannot be used for '", scale$aesthetics, "'.")
185185

186186
guide$title <- scale$make_title(guide$title %|W|% scale$name %|W|% labels[[output]])

R/position-stack.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ PositionFill <- ggproto("PositionFill", PositionStack,
225225

226226
stack_var <- function(data) {
227227
if (!is.null(data$ymax)) {
228-
if (any(data$ymin != 0 && data$ymax != 0, na.rm = TRUE)) {
228+
if (any(data$ymin != 0 & data$ymax != 0, na.rm = TRUE)) {
229229
warning("Stacking not well defined when not anchored on the axis", call. = FALSE)
230230
}
231231
"ymax"

R/scale-.r

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ continuous_scale <- function(aesthetics, scale_name, palette, name = waiver(),
562562

563563
position <- match.arg(position, c("left", "right", "top", "bottom"))
564564

565-
if (is.null(breaks) && !is_position_aes(aesthetics) && guide != "none") {
565+
# If the scale is non-positional, break = NULL means removing the guide
566+
if (is.null(breaks) && all(!is_position_aes(aesthetics))) {
566567
guide <- "none"
567568
}
568569

@@ -633,7 +634,8 @@ discrete_scale <- function(aesthetics, scale_name, palette, name = waiver(),
633634

634635
position <- match.arg(position, c("left", "right", "top", "bottom"))
635636

636-
if (is.null(breaks) && !is_position_aes(aesthetics) && guide != "none") {
637+
# If the scale is non-positional, break = NULL means removing the guide
638+
if (is.null(breaks) && all(!is_position_aes(aesthetics))) {
637639
guide <- "none"
638640
}
639641

0 commit comments

Comments
 (0)