Skip to content

Commit d8eb945

Browse files
fix some lints (#6050)
1 parent 633e350 commit d8eb945

40 files changed

+85
-85
lines changed

R/annotation-logticks.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
165165

166166
names(xticks)[names(xticks) == "value"] <- x_name # Rename to 'x' for coordinates$transform
167167
xticks <- coord$transform(xticks, panel_params)
168-
xticks = xticks[xticks$x <= 1 & xticks$x >= 0,]
168+
xticks <- xticks[xticks$x <= 1 & xticks$x >= 0,]
169169

170170
if (outside)
171171
xticks$end = -xticks$end
@@ -203,7 +203,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
203203

204204
names(yticks)[names(yticks) == "value"] <- y_name # Rename to 'y' for coordinates$transform
205205
yticks <- coord$transform(yticks, panel_params)
206-
yticks = yticks[yticks$y <= 1 & yticks$y >= 0,]
206+
yticks <- yticks[yticks$y <= 1 & yticks$y >= 0,]
207207

208208
if (outside)
209209
yticks$end = -yticks$end
@@ -238,7 +238,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
238238
# - start: on the other axis, start position of the line (usually 0)
239239
# - end: on the other axis, end position of the line (for example, .1, .2, or .3)
240240
calc_logticks <- function(base = 10, ticks_per_base = base - 1,
241-
minpow = 0, maxpow = minpow + 1, start = 0, shortend = .1, midend = .2, longend = .3) {
241+
minpow = 0, maxpow = minpow + 1, start = 0, shortend = 0.1, midend = 0.2, longend = 0.3) {
242242

243243
# Number of blocks of tick marks
244244
reps <- maxpow - minpow

R/bin.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
165165
}
166166

167167
# Add row for missings
168-
if (any(is.na(bins))) {
168+
if (anyNA(bins)) {
169169
bin_count <- c(bin_count, sum(is.na(bins)))
170170
bin_widths <- c(bin_widths, NA)
171171
bin_x <- c(bin_x, NA)

R/compat-plyr.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ rename <- function(x, replace) {
5454
id_var <- function(x, drop = FALSE) {
5555
if (length(x) == 0) {
5656
id <- integer()
57-
n = 0L
57+
n <- 0L
5858
} else if (!is.null(attr(x, "n")) && !drop) {
5959
return(x)
6060
} else if (is.factor(x) && !drop) {
6161
x <- addNA(x, ifany = TRUE)
6262
id <- as.integer(x)
63-
n <- length(levels(x))
63+
n <- nlevels(x)
6464
} else {
6565
levels <- sort(unique0(x), na.last = TRUE)
6666
id <- match(x, levels)

R/coord-polar.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ CoordPolar <- ggproto("CoordPolar", Coord,
137137
ret[[n]]$sec.labels <- out$sec.labels
138138
}
139139

140-
details = list(
140+
details <- list(
141141
x.range = ret$x$range, y.range = ret$y$range,
142142
x.major = ret$x$major, y.major = ret$y$major,
143143
x.minor = ret$x$minor, y.minor = ret$y$minor,

R/coord-sf.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ sf_rescale01 <- function(x, x_range, y_range) {
416416

417417
# different limits methods
418418
calc_limits_bbox <- function(method, xlim, ylim, crs, default_crs) {
419-
if (any(!is.finite(c(xlim, ylim))) && method != "geometry_bbox") {
419+
if (!all(is.finite(c(xlim, ylim))) && method != "geometry_bbox") {
420420
cli::cli_abort(c(
421421
"Scale limits cannot be mapped onto spatial coordinates in {.fn coord_sf}.",
422422
"i" = "Consider setting {.code lims_method = \"geometry_bbox\"} or {.code default_crs = NULL}."
@@ -585,7 +585,7 @@ coord_sf <- function(xlim = NULL, ylim = NULL, expand = TRUE,
585585
}
586586

587587
parse_axes_labeling <- function(x) {
588-
labs = unlist(strsplit(x, ""))
588+
labs <- unlist(strsplit(x, ""))
589589
list(top = labs[1], right = labs[2], bottom = labs[3], left = labs[4])
590590
}
591591

R/facet-.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ find_panel <- function(table) {
678678
}
679679
#' @rdname find_panel
680680
#' @export
681-
panel_cols = function(table) {
681+
panel_cols <- function(table) {
682682
panels <- table$layout[grepl("^panel", table$layout$name), , drop = FALSE]
683683
unique0(panels[, c('l', 'r')])
684684
}

R/facet-grid-.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ FacetGrid <- ggproto("FacetGrid", Facet,
319319
if (length(missing_facets) > 0) {
320320
to_add <- unique0(layout[missing_facets])
321321

322-
data_rep <- rep.int(1:nrow(data), nrow(to_add))
323-
facet_rep <- rep(1:nrow(to_add), each = nrow(data))
322+
data_rep <- rep.int(seq_len(nrow(data)), nrow(to_add))
323+
facet_rep <- rep(seq_len(nrow(to_add)), each = nrow(data))
324324

325325
data <- unrowname(data[data_rep, , drop = FALSE])
326326
facet_vals <- unrowname(vec_cbind(

R/facet-wrap.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ FacetWrap <- ggproto("FacetWrap", Facet,
242242

243243
to_add <- unique0(layout[missing_facets])
244244

245-
data_rep <- rep.int(1:nrow(data), nrow(to_add))
246-
facet_rep <- rep(1:nrow(to_add), each = nrow(data))
245+
data_rep <- rep.int(seq_len(nrow(data)), nrow(to_add))
246+
facet_rep <- rep(seq_len(nrow(to_add)), each = nrow(data))
247247

248248
data <- data[data_rep, , drop = FALSE]
249249
facet_vals <- vec_cbind(

R/fortify-spatial.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fortify.Polygons <- function(model, data, ...) {
7171
})
7272
pieces <- vec_rbind0(!!!pieces)
7373

74-
pieces$order <- 1:nrow(pieces)
74+
pieces$order <- seq_len(nrow(pieces))
7575
pieces$id <- model@ID
7676
pieces$piece <- factor(pieces$piece)
7777
pieces$group <- interaction(pieces$id, pieces$piece)
@@ -89,7 +89,7 @@ fortify.Polygon <- function(model, data, ...) {
8989

9090
df <- as.data.frame(model@coords)
9191
names(df) <- c("long", "lat")
92-
df$order <- 1:nrow(df)
92+
df$order <- seq_len(nrow(df))
9393
df$hole <- model@hole
9494
df
9595
}
@@ -124,7 +124,7 @@ fortify.Lines <- function(model, data, ...) {
124124
})
125125
pieces <- vec_rbind0(!!!pieces)
126126

127-
pieces$order <- 1:nrow(pieces)
127+
pieces$order <- seq_len(nrow(pieces))
128128
pieces$id <- model@ID
129129
pieces$piece <- factor(pieces$piece)
130130
pieces$group <- interaction(pieces$id, pieces$piece)
@@ -142,7 +142,7 @@ fortify.Line <- function(model, data, ...) {
142142

143143
df <- as.data.frame(model@coords)
144144
names(df) <- c("long", "lat")
145-
df$order <- 1:nrow(df)
145+
df$order <- seq_len(nrow(df))
146146
df
147147
}
148148

R/geom-dotplot.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,25 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
197197

198198
# Set up the stacking function and range
199199
if (is.null(params$stackdir) || params$stackdir == "up") {
200-
stackdots <- function(a) a - .5
200+
stackdots <- function(a) a - 0.5
201201
stackaxismin <- 0
202202
stackaxismax <- 1
203203
} else if (params$stackdir == "down") {
204-
stackdots <- function(a) -a + .5
204+
stackdots <- function(a) -a + 0.5
205205
stackaxismin <- -1
206206
stackaxismax <- 0
207207
} else if (params$stackdir == "center") {
208208
stackdots <- function(a) a - 1 - max(a - 1) / 2
209-
stackaxismin <- -.5
210-
stackaxismax <- .5
209+
stackaxismin <- -0.5
210+
stackaxismax <- 0.5
211211
} else if (params$stackdir == "centerwhole") {
212212
stackdots <- function(a) a - 1 - floor(max(a - 1) / 2)
213-
stackaxismin <- -.5
214-
stackaxismax <- .5
213+
stackaxismin <- -0.5
214+
stackaxismax <- 0.5
215215
}
216216

217217
# Fill the bins: at a given x (or y), if count=3, make 3 entries at that x
218-
data <- data[rep(1:nrow(data), data$count), ]
218+
data <- data[rep(seq_len(nrow(data)), data$count), ]
219219

220220
# Next part will set the position of each dot within each stack
221221
# If stackgroups=TRUE, split only on x (or y) and panel; if not stacking, also split by group
@@ -231,7 +231,7 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
231231

232232
# Within each x, or x+group, set countidx=1,2,3, and set stackpos according to stack function
233233
data <- dapply(data, plyvars, function(xx) {
234-
xx$countidx <- 1:nrow(xx)
234+
xx$countidx <- seq_len(nrow(xx))
235235
xx$stackpos <- stackdots(xx$countidx)
236236
xx
237237
})
@@ -281,11 +281,11 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
281281
binaxis <- ifelse(binaxis == "x", "y", "x")
282282

283283
if (binaxis == "x") {
284-
stackaxis = "y"
284+
stackaxis <- "y"
285285
dotdianpc <- dotsize * tdata$binwidth[1] / (max(panel_params$x.range) - min(panel_params$x.range))
286286

287287
} else if (binaxis == "y") {
288-
stackaxis = "x"
288+
stackaxis <- "x"
289289
dotdianpc <- dotsize * tdata$binwidth[1] / (max(panel_params$y.range) - min(panel_params$y.range))
290290
}
291291

R/geom-label.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ GeomLabel <- ggproto("GeomLabel", Geom,
8181

8282
size.unit <- resolve_text_unit(size.unit)
8383

84-
grobs <- lapply(1:nrow(data), function(i) {
84+
grobs <- lapply(seq_len(nrow(data)), function(i) {
8585
row <- data[i, , drop = FALSE]
8686
labelGrob(lab[i],
8787
x = unit(row$x, "native"),

R/geom-segment.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ GeomSegment <- ggproto("GeomSegment", Geom,
134134
))
135135
}
136136

137-
data$group <- 1:nrow(data)
137+
data$group <- seq_len(nrow(data))
138138
starts <- subset(data, select = c(-xend, -yend))
139139
ends <- rename(subset(data, select = c(-x, -y)), c("xend" = "x", "yend" = "y"))
140140

R/geom-smooth.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ GeomSmooth <- ggproto("GeomSmooth", Geom,
153153
ribbon <- transform(data, colour = NA)
154154
path <- transform(data, alpha = NA)
155155

156-
ymin = flipped_names(flipped_aes)$ymin
157-
ymax = flipped_names(flipped_aes)$ymax
156+
ymin <- flipped_names(flipped_aes)$ymin
157+
ymax <- flipped_names(flipped_aes)$ymax
158158
has_ribbon <- se && !is.null(data[[ymax]]) && !is.null(data[[ymin]])
159159

160160
gList(

R/guide-.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ Guide <- ggproto(
487487

488488
# Helper function that may facilitate flipping theme elements by
489489
# swapping x/y related arguments to `element_grob()`
490-
flip_element_grob = function(..., flip = FALSE) {
490+
flip_element_grob <- function(..., flip = FALSE) {
491491
if (!flip) {
492492
ans <- element_grob(...)
493493
return(ans)
@@ -499,7 +499,7 @@ flip_element_grob = function(..., flip = FALSE) {
499499
}
500500

501501
# The flippable arguments for `flip_element_grob()`.
502-
flip_names = c(
502+
flip_names <- c(
503503
"x" = "y",
504504
"y" = "x",
505505
"width" = "height",

R/guide-axis-stack.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ guide_axis_stack <- function(first = "axis", ..., title = waiver(), theme = NULL
4141
# Check available aesthetics
4242
available <- lapply(axes, `[[`, name = "available_aes")
4343
available <- vapply(available, function(x) all(c("x", "y") %in% x), logical(1))
44-
if (all(!available)) {
44+
if (!any(available)) {
4545
cli::cli_abort(paste0(
4646
"{.fn guide_axis_stack} can only use guides that handle {.field x} and ",
4747
"{.field y} aesthetics."
4848
))
4949
}
5050

5151
# Remove guides that don't support x/y aesthetics
52-
if (any(!available)) {
52+
if (!all(available)) {
5353
remove <- which(!available)
5454
removed <- vapply(axes[remove], snake_class, character(1))
5555
axes[remove] <- NULL

R/guide-axis.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -592,23 +592,23 @@ axis_label_element_overrides <- function(axis_position, angle = NULL) {
592592

593593
if (axis_position == "bottom") {
594594

595-
hjust = if (angle %in% c(0, 180)) 0.5 else if (angle < 180) 1 else 0
596-
vjust = if (angle %in% c(90, 270)) 0.5 else if (angle > 90 & angle < 270) 0 else 1
595+
hjust <- if (angle %in% c(0, 180)) 0.5 else if (angle < 180) 1 else 0
596+
vjust <- if (angle %in% c(90, 270)) 0.5 else if (angle > 90 & angle < 270) 0 else 1
597597

598598
} else if (axis_position == "left") {
599599

600-
hjust = if (angle %in% c(90, 270)) 0.5 else if (angle > 90 & angle < 270) 0 else 1
601-
vjust = if (angle %in% c(0, 180)) 0.5 else if (angle < 180) 0 else 1
600+
hjust <- if (angle %in% c(90, 270)) 0.5 else if (angle > 90 & angle < 270) 0 else 1
601+
vjust <- if (angle %in% c(0, 180)) 0.5 else if (angle < 180) 0 else 1
602602

603603
} else if (axis_position == "top") {
604604

605-
hjust = if (angle %in% c(0, 180)) 0.5 else if (angle < 180) 0 else 1
606-
vjust = if (angle %in% c(90, 270)) 0.5 else if (angle > 90 & angle < 270) 1 else 0
605+
hjust <- if (angle %in% c(0, 180)) 0.5 else if (angle < 180) 0 else 1
606+
vjust <- if (angle %in% c(90, 270)) 0.5 else if (angle > 90 & angle < 270) 1 else 0
607607

608608
} else if (axis_position == "right") {
609609

610-
hjust = if (angle %in% c(90, 270)) 0.5 else if (angle > 90 & angle < 270) 1 else 0
611-
vjust = if (angle %in% c(0, 180)) 0.5 else if (angle < 180) 1 else 0
610+
hjust <- if (angle %in% c(90, 270)) 0.5 else if (angle > 90 & angle < 270) 1 else 0
611+
vjust <- if (angle %in% c(0, 180)) 0.5 else if (angle < 180) 1 else 0
612612

613613
}
614614

R/guide-bins.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ GuideBins <- ggproto(
326326
}
327327
)
328328

329-
parse_binned_breaks = function(scale, breaks = scale$get_breaks()) {
329+
parse_binned_breaks <- function(scale, breaks = scale$get_breaks()) {
330330

331331
breaks <- breaks[!is.na(breaks)]
332332
if (length(breaks) == 0) {

R/guide-colorbar.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,12 @@ GuideColourbar <- ggproto(
366366
if (params$direction == "horizontal") {
367367
width <- 1 / nrow(decor)
368368
height <- 1
369-
x <- (seq(nrow(decor)) - 1) * width
369+
x <- (seq_len(nrow(decor)) - 1) * width
370370
y <- 0
371371
} else {
372372
width <- 1
373373
height <- 1 / nrow(decor)
374-
y <- (seq(nrow(decor)) - 1) * height
374+
y <- (seq_len(nrow(decor)) - 1) * height
375375
x <- 0
376376
}
377377
grob <- rectGrob(

R/guide-legend.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ keep_key_data <- function(key, data, aes, show) {
631631
if (isTRUE(any(show)) || length(show) == 0) {
632632
return(TRUE)
633633
}
634-
if (isTRUE(all(!show))) {
634+
if (isTRUE(!any(show))) {
635635
return(FALSE)
636636
}
637637
# Second, we go find if the value is actually present in the data.

R/guides-.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Guides <- ggproto(
194194
if (is.character(index)) {
195195
index <- match(index, self$aesthetics)
196196
}
197-
if (any(is.na(index)) || length(index) == 0) {
197+
if (anyNA(index) || length(index) == 0) {
198198
return(NULL)
199199
}
200200
if (length(index) == 1) {
@@ -209,7 +209,7 @@ Guides <- ggproto(
209209
if (is.character(index)) {
210210
index <- match(index, self$aesthetics)
211211
}
212-
if (any(is.na(index)) || length(index) == 0) {
212+
if (anyNA(index) || length(index) == 0) {
213213
return(NULL)
214214
}
215215
if (length(index) == 1) {

R/legend-draw.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ draw_key_vpath <- function(data, params, size) {
207207
#' @export
208208
#' @rdname draw_key
209209
draw_key_dotplot <- function(data, params, size) {
210-
pointsGrob(0.5, 0.5, size = unit(.5, "npc"),
210+
pointsGrob(0.5, 0.5, size = unit(0.5, "npc"),
211211
pch = 21,
212212
gp = gg_par(
213213
col = alpha(data$colour %||% "black", data$alpha),

R/limits.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ limits.numeric <- function(lims, var, call = caller_env()) {
116116
if (length(lims) != 2) {
117117
cli::cli_abort("{.arg {var}} must be a two-element vector.", call = call)
118118
}
119-
if (!any(is.na(lims)) && lims[1] > lims[2]) {
119+
if (!anyNA(lims) && lims[1] > lims[2]) {
120120
trans <- "reverse"
121121
} else {
122122
trans <- "identity"

R/margins.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ justify_grobs <- function(grobs, x = NULL, y = NULL, hjust = 0.5, vjust = 0.5,
198198
)
199199
}
200200
else {
201-
children = gList(grobs)
201+
children <- gList(grobs)
202202
}
203203

204204

0 commit comments

Comments
 (0)