Skip to content

Commit

Permalink
fix some lints
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Aug 20, 2024
1 parent 633e350 commit e83eb22
Show file tree
Hide file tree
Showing 40 changed files with 85 additions and 85 deletions.
6 changes: 3 additions & 3 deletions R/annotation-logticks.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,

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

if (outside)
xticks$end = -xticks$end
Expand Down Expand Up @@ -203,7 +203,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,

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

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

# Number of blocks of tick marks
reps <- maxpow - minpow
Expand Down
2 changes: 1 addition & 1 deletion R/bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
}

# Add row for missings
if (any(is.na(bins))) {
if (anyNA(bins)) {
bin_count <- c(bin_count, sum(is.na(bins)))
bin_widths <- c(bin_widths, NA)
bin_x <- c(bin_x, NA)
Expand Down
4 changes: 2 additions & 2 deletions R/compat-plyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ rename <- function(x, replace) {
id_var <- function(x, drop = FALSE) {
if (length(x) == 0) {
id <- integer()
n = 0L
n <- 0L
} else if (!is.null(attr(x, "n")) && !drop) {
return(x)
} else if (is.factor(x) && !drop) {
x <- addNA(x, ifany = TRUE)
id <- as.integer(x)
n <- length(levels(x))
n <- nlevels(x)
} else {
levels <- sort(unique0(x), na.last = TRUE)
id <- match(x, levels)
Expand Down
2 changes: 1 addition & 1 deletion R/coord-polar.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ CoordPolar <- ggproto("CoordPolar", Coord,
ret[[n]]$sec.labels <- out$sec.labels
}

details = list(
details <- list(
x.range = ret$x$range, y.range = ret$y$range,
x.major = ret$x$major, y.major = ret$y$major,
x.minor = ret$x$minor, y.minor = ret$y$minor,
Expand Down
4 changes: 2 additions & 2 deletions R/coord-sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ sf_rescale01 <- function(x, x_range, y_range) {

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

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

Expand Down
2 changes: 1 addition & 1 deletion R/facet-.R
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ find_panel <- function(table) {
}
#' @rdname find_panel
#' @export
panel_cols = function(table) {
panel_cols <- function(table) {
panels <- table$layout[grepl("^panel", table$layout$name), , drop = FALSE]
unique0(panels[, c('l', 'r')])
}
Expand Down
4 changes: 2 additions & 2 deletions R/facet-grid-.R
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ FacetGrid <- ggproto("FacetGrid", Facet,
if (length(missing_facets) > 0) {
to_add <- unique0(layout[missing_facets])

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

data <- unrowname(data[data_rep, , drop = FALSE])
facet_vals <- unrowname(vec_cbind(
Expand Down
4 changes: 2 additions & 2 deletions R/facet-wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ FacetWrap <- ggproto("FacetWrap", Facet,

to_add <- unique0(layout[missing_facets])

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

data <- data[data_rep, , drop = FALSE]
facet_vals <- vec_cbind(
Expand Down
8 changes: 4 additions & 4 deletions R/fortify-spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fortify.Polygons <- function(model, data, ...) {
})
pieces <- vec_rbind0(!!!pieces)

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

df <- as.data.frame(model@coords)
names(df) <- c("long", "lat")
df$order <- 1:nrow(df)
df$order <- seq_len(nrow(df))
df$hole <- model@hole
df
}
Expand Down Expand Up @@ -124,7 +124,7 @@ fortify.Lines <- function(model, data, ...) {
})
pieces <- vec_rbind0(!!!pieces)

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

df <- as.data.frame(model@coords)
names(df) <- c("long", "lat")
df$order <- 1:nrow(df)
df$order <- seq_len(nrow(df))
df
}

Expand Down
20 changes: 10 additions & 10 deletions R/geom-dotplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,25 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,

# Set up the stacking function and range
if (is.null(params$stackdir) || params$stackdir == "up") {
stackdots <- function(a) a - .5
stackdots <- function(a) a - 0.5
stackaxismin <- 0
stackaxismax <- 1
} else if (params$stackdir == "down") {
stackdots <- function(a) -a + .5
stackdots <- function(a) -a + 0.5
stackaxismin <- -1
stackaxismax <- 0
} else if (params$stackdir == "center") {
stackdots <- function(a) a - 1 - max(a - 1) / 2
stackaxismin <- -.5
stackaxismax <- .5
stackaxismin <- -0.5
stackaxismax <- 0.5
} else if (params$stackdir == "centerwhole") {
stackdots <- function(a) a - 1 - floor(max(a - 1) / 2)
stackaxismin <- -.5
stackaxismax <- .5
stackaxismin <- -0.5
stackaxismax <- 0.5
}

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

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion R/geom-label.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ GeomLabel <- ggproto("GeomLabel", Geom,

size.unit <- resolve_text_unit(size.unit)

grobs <- lapply(1:nrow(data), function(i) {
grobs <- lapply(seq_len(nrow(data)), function(i) {
row <- data[i, , drop = FALSE]
labelGrob(lab[i],
x = unit(row$x, "native"),
Expand Down
2 changes: 1 addition & 1 deletion R/geom-segment.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ GeomSegment <- ggproto("GeomSegment", Geom,
))
}

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

Expand Down
4 changes: 2 additions & 2 deletions R/geom-smooth.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ GeomSmooth <- ggproto("GeomSmooth", Geom,
ribbon <- transform(data, colour = NA)
path <- transform(data, alpha = NA)

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

gList(
Expand Down
4 changes: 2 additions & 2 deletions R/guide-.R
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ Guide <- ggproto(

# Helper function that may facilitate flipping theme elements by
# swapping x/y related arguments to `element_grob()`
flip_element_grob = function(..., flip = FALSE) {
flip_element_grob <- function(..., flip = FALSE) {
if (!flip) {
ans <- element_grob(...)
return(ans)
Expand All @@ -499,7 +499,7 @@ flip_element_grob = function(..., flip = FALSE) {
}

# The flippable arguments for `flip_element_grob()`.
flip_names = c(
flip_names <- c(
"x" = "y",
"y" = "x",
"width" = "height",
Expand Down
4 changes: 2 additions & 2 deletions R/guide-axis-stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ guide_axis_stack <- function(first = "axis", ..., title = waiver(), theme = NULL
# Check available aesthetics
available <- lapply(axes, `[[`, name = "available_aes")
available <- vapply(available, function(x) all(c("x", "y") %in% x), logical(1))
if (all(!available)) {
if (!any(available)) {
cli::cli_abort(paste0(
"{.fn guide_axis_stack} can only use guides that handle {.field x} and ",
"{.field y} aesthetics."
))
}

# Remove guides that don't support x/y aesthetics
if (any(!available)) {
if (!all(available)) {
remove <- which(!available)
removed <- vapply(axes[remove], snake_class, character(1))
axes[remove] <- NULL
Expand Down
16 changes: 8 additions & 8 deletions R/guide-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -592,23 +592,23 @@ axis_label_element_overrides <- function(axis_position, angle = NULL) {

if (axis_position == "bottom") {

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

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

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

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

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

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

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

}

Expand Down
2 changes: 1 addition & 1 deletion R/guide-bins.R
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ GuideBins <- ggproto(
}
)

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

breaks <- breaks[!is.na(breaks)]
if (length(breaks) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions R/guide-colorbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@ GuideColourbar <- ggproto(
if (params$direction == "horizontal") {
width <- 1 / nrow(decor)
height <- 1
x <- (seq(nrow(decor)) - 1) * width
x <- (seq_len(nrow(decor)) - 1) * width
y <- 0
} else {
width <- 1
height <- 1 / nrow(decor)
y <- (seq(nrow(decor)) - 1) * height
y <- (seq_len(nrow(decor)) - 1) * height
x <- 0
}
grob <- rectGrob(
Expand Down
2 changes: 1 addition & 1 deletion R/guide-legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ keep_key_data <- function(key, data, aes, show) {
if (isTRUE(any(show)) || length(show) == 0) {
return(TRUE)
}
if (isTRUE(all(!show))) {
if (isTRUE(!any(show))) {
return(FALSE)
}
# Second, we go find if the value is actually present in the data.
Expand Down
4 changes: 2 additions & 2 deletions R/guides-.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Guides <- ggproto(
if (is.character(index)) {
index <- match(index, self$aesthetics)
}
if (any(is.na(index)) || length(index) == 0) {
if (anyNA(index) || length(index) == 0) {
return(NULL)
}
if (length(index) == 1) {
Expand All @@ -209,7 +209,7 @@ Guides <- ggproto(
if (is.character(index)) {
index <- match(index, self$aesthetics)
}
if (any(is.na(index)) || length(index) == 0) {
if (anyNA(index) || length(index) == 0) {
return(NULL)
}
if (length(index) == 1) {
Expand Down
2 changes: 1 addition & 1 deletion R/legend-draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ draw_key_vpath <- function(data, params, size) {
#' @export
#' @rdname draw_key
draw_key_dotplot <- function(data, params, size) {
pointsGrob(0.5, 0.5, size = unit(.5, "npc"),
pointsGrob(0.5, 0.5, size = unit(0.5, "npc"),
pch = 21,
gp = gg_par(
col = alpha(data$colour %||% "black", data$alpha),
Expand Down
2 changes: 1 addition & 1 deletion R/limits.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ limits.numeric <- function(lims, var, call = caller_env()) {
if (length(lims) != 2) {
cli::cli_abort("{.arg {var}} must be a two-element vector.", call = call)
}
if (!any(is.na(lims)) && lims[1] > lims[2]) {
if (!anyNA(lims) && lims[1] > lims[2]) {
trans <- "reverse"
} else {
trans <- "identity"
Expand Down
2 changes: 1 addition & 1 deletion R/margins.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ justify_grobs <- function(grobs, x = NULL, y = NULL, hjust = 0.5, vjust = 0.5,
)
}
else {
children = gList(grobs)
children <- gList(grobs)
}


Expand Down
Loading

0 comments on commit e83eb22

Please sign in to comment.