Skip to content

A big lint #6127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b5b2a48
spaces for infix operators
teunbrand Sep 30, 2024
0777b42
comma spacing
teunbrand Sep 30, 2024
3a4bd4b
fix braces
teunbrand Sep 30, 2024
fe1d779
consistently use double quotes
teunbrand Sep 30, 2024
6a1971d
do not use semicolons
teunbrand Sep 30, 2024
869d0fa
arrow assignment
teunbrand Sep 30, 2024
4c60688
remove trailing blank lines
teunbrand Sep 30, 2024
ac43f60
Replace 1:nrow(x) by vec_seq_along
teunbrand Sep 30, 2024
d1d80a7
scalar logic operators
teunbrand Sep 30, 2024
cb580ff
few more spaces
teunbrand Sep 30, 2024
7bef542
Unquote syntactically valid names, backtick function names
teunbrand Sep 30, 2024
1d51028
fix static regexes
teunbrand Sep 30, 2024
f0f2e33
remove weird spaces
teunbrand Sep 30, 2024
f548916
fix message
teunbrand Sep 30, 2024
bd8140b
remove redundant c()
teunbrand Sep 30, 2024
44605e1
cleanup needlessly nested `if` statements
teunbrand Sep 30, 2024
8358a3b
reindent
teunbrand Oct 1, 2024
262265d
swap 'if not' blocks to if blocks
teunbrand Oct 1, 2024
c8a2b5f
review implicit assignment
teunbrand Oct 1, 2024
a51fa41
replace `paste(sep = "")` with `paste0()`
teunbrand Oct 1, 2024
1fd754c
fix trailing commas
teunbrand Oct 1, 2024
3eec144
remove redundant anonymity
teunbrand Oct 1, 2024
61798f9
redundant `==`
teunbrand Oct 1, 2024
dc028b1
drop duplicate arguments
teunbrand Oct 1, 2024
7a8a98a
mapply -> Map and sapply -> vapply
teunbrand Oct 1, 2024
612f0b2
use proper comparison expectations
teunbrand Oct 1, 2024
dcdc681
misc tweaks
teunbrand Oct 1, 2024
9c7d168
use cheaper data.frame in tests
teunbrand Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions R/aes.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,24 @@ print.uneval <- function(x, ...) {
}

#' @export
"[.uneval" <- function(x, i, ...) {
`[.uneval` <- function(x, i, ...) {
new_aes(NextMethod())
}

# If necessary coerce replacements to quosures for compatibility
#' @export
"[[<-.uneval" <- function(x, i, value) {
`[[<-.uneval` <- function(x, i, value) {
new_aes(NextMethod())
}
#' @export
"$<-.uneval" <- function(x, i, value) {
`$<-.uneval` <- function(x, i, value) {
# Can't use NextMethod() because of a bug in R 3.1
x <- unclass(x)
x[[i]] <- value
new_aes(x)
}
#' @export
"[<-.uneval" <- function(x, i, value) {
`[<-.uneval` <- function(x, i, value) {
new_aes(NextMethod())
}

Expand Down Expand Up @@ -419,7 +419,7 @@ warn_for_aes_extract_usage_expr <- function(x, data, env = emptyenv()) {
good_usage <- alternative_aes_extract_usage(x)
cli::cli_warn(c(
"Use of {.code {format(x)}} is discouraged.",
"i" = "Use {.code {good_usage}} instead."
i = "Use {.code {good_usage}} instead."
))
}
} else if (is.call(x)) {
Expand Down
2 changes: 1 addition & 1 deletion R/annotation-custom.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ GeomCustomAnn <- ggproto("GeomCustomAnn", Geom,

vp <- viewport(x = mean(x_rng), y = mean(y_rng),
width = diff(x_rng), height = diff(y_rng),
just = c("center","center"))
just = c("center", "center"))
editGrob(grob, vp = vp, name = paste(grob$name, annotation_id()))
},

Expand Down
37 changes: 20 additions & 17 deletions R/annotation-logticks.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@
#' mid = unit(3,"mm"),
#' long = unit(4,"mm")
#' )
annotation_logticks <- function(base = 10, sides = "bl", outside = FALSE, scaled = TRUE,
annotation_logticks <- function(
base = 10, sides = "bl", outside = FALSE, scaled = TRUE,
short = unit(0.1, "cm"), mid = unit(0.2, "cm"), long = unit(0.3, "cm"),
colour = "black", linewidth = 0.5, linetype = 1, alpha = 1, color = NULL, ...,
size = deprecated())
{
size = deprecated()) {

if (!is.null(color))
colour <- color

Expand Down Expand Up @@ -135,8 +136,8 @@

draw_panel = function(data, panel_params, coord, base = 10, sides = "bl",
outside = FALSE, scaled = TRUE, short = unit(0.1, "cm"),
mid = unit(0.2, "cm"), long = unit(0.3, "cm"))
{
mid = unit(0.2, "cm"), long = unit(0.3, "cm")) {

ticks <- list()
flipped <- inherits(coord, "CoordFlip")
x_name <- if (flipped) "y" else "x"
Expand Down Expand Up @@ -165,20 +166,20 @@

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
xticks$end <- -xticks$end

# Make the grobs
if (grepl("b", sides) && nrow(xticks) > 0) {
if (grepl("b", sides, fixed = TRUE) && nrow(xticks) > 0) {
ticks$x_b <- with(data, segmentsGrob(
x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"),
y0 = unit(xticks$start, "cm"), y1 = unit(xticks$end, "cm"),
gp = gg_par(col = alpha(colour, alpha), lty = linetype, lwd = linewidth)
))
}
if (grepl("t", sides) && nrow(xticks) > 0) {
if (grepl("t", sides, fixed = TRUE) && nrow(xticks) > 0) {
ticks$x_t <- with(data, segmentsGrob(
x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"),
y0 = unit(1, "npc") - unit(xticks$start, "cm"), y1 = unit(1, "npc") - unit(xticks$end, "cm"),
Expand All @@ -203,20 +204,20 @@

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
yticks$end <- -yticks$end

# Make the grobs
if (grepl("l", sides) && nrow(yticks) > 0) {
if (grepl("l", sides, fixed = TRUE) && nrow(yticks) > 0) {
ticks$y_l <- with(data, segmentsGrob(
y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"),
x0 = unit(yticks$start, "cm"), x1 = unit(yticks$end, "cm"),
gp = gg_par(col = alpha(colour, alpha), lty = linetype, lwd = linewidth)
))
}
if (grepl("r", sides) && nrow(yticks) > 0) {
if (grepl("r", sides, fixed = TRUE) && nrow(yticks) > 0) {
ticks$y_r <- with(data, segmentsGrob(
y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"),
x0 = unit(1, "npc") - unit(yticks$start, "cm"), x1 = unit(1, "npc") - unit(yticks$end, "cm"),
Expand All @@ -242,8 +243,10 @@
# - value: the position of the log tick on the data axis, for example 1, 2, ..., 9, 10, 20, ...
# - 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 = 0.1, midend = 0.2, longend = 0.3) {
calc_logticks <- function(
base = 10, ticks_per_base = base - 1,
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 All @@ -268,8 +271,8 @@

# Where to place the longer tick marks that are between each base
# For base 10, this will be at each 5
longtick_after_base <- floor(ticks_per_base/2)
tickend[ cycleIdx == longtick_after_base ] <- midend
longtick_after_base <- floor(ticks_per_base / 2)
tickend[cycleIdx == longtick_after_base] <- midend

Check warning on line 275 in R/annotation-logticks.R

View check run for this annotation

Codecov / codecov/patch

R/annotation-logticks.R#L274-L275

Added lines #L274 - L275 were not covered by tests

tickdf <- data_frame0(
value = ticks,
Expand Down
5 changes: 3 additions & 2 deletions R/annotation-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ GeomAnnotationMap <- ggproto("GeomAnnotationMap", GeomMap,
id = grob_id,
gp = gg_par(
col = data$colour, fill = alpha(data$fill, data$alpha),
lwd = data$linewidth)
lwd = data$linewidth
)
)
},

required_aes = c()
required_aes = NULL
)
8 changes: 5 additions & 3 deletions R/annotation-raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ NULL
#' geom_point()
annotation_raster <- function(raster, xmin, xmax, ymin, ymax,
interpolate = FALSE) {
if (!inherits(raster, 'nativeRaster'))
if (!inherits(raster, "nativeRaster"))
raster <- grDevices::as.raster(raster)

layer(
Expand Down Expand Up @@ -86,8 +86,10 @@ GeomRasterAnn <- ggproto("GeomRasterAnn", Geom,
x_rng <- range(data$x, na.rm = TRUE)
y_rng <- range(data$y, na.rm = TRUE)

rasterGrob(raster, x_rng[1], y_rng[1],
rasterGrob(
raster, x_rng[1], y_rng[1],
diff(x_rng), diff(y_rng), default.units = "native",
just = c("left","bottom"), interpolate = interpolate)
just = c("left", "bottom"), interpolate = interpolate
)
}
)
3 changes: 1 addition & 2 deletions R/annotation.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ annotate <- function(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL,
if (is_string(geom, c("abline", "hline", "vline"))) {
cli::cli_warn(c(
"{.arg geom} must not be {.val {geom}}.",
"i" = "Please use {.fn {paste0('geom_', geom)}} directly instead."
i = "Please use {.fn {paste0('geom_', geom)}} directly instead."
))
}

Expand Down Expand Up @@ -95,4 +95,3 @@ annotate <- function(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL,
show.legend = FALSE
)
}

3 changes: 1 addition & 2 deletions R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ autoplot <- function(object, ...) {
autoplot.default <- function(object, ...) {
cli::cli_abort(c(
"Objects of class {.cls {class(object)[[1]]}} are not supported by autoplot.",
"i" = "Have you loaded the required package?"
i = "Have you loaded the required package?"
))
}

39 changes: 20 additions & 19 deletions R/axis-secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
}

# sec_axis() historically accepted two-sided formula, so be permissive.
if (length(transform) > 2) transform <- transform[c(1,3)]
if (length(transform) > 2) transform <- transform[c(1, 3)]

transform <- as_function(transform)
ggproto(NULL, AxisSecondary,
Expand All @@ -130,12 +130,12 @@

set_sec_axis <- function(sec.axis, scale) {
if (!is.waive(sec.axis)) {
if (scale$is_discrete()) {
if (!identical(.subset2(sec.axis, "trans"), identity)) {
cli::cli_abort("Discrete secondary axes must have the {.fn identity} transformation.")
}
if (scale$is_discrete() && !identical(.subset2(sec.axis, "trans"), identity)) {
cli::cli_abort("Discrete secondary axes must have the {.fn identity} transformation.")

Check warning on line 134 in R/axis-secondary.R

View check run for this annotation

Codecov / codecov/patch

R/axis-secondary.R#L134

Added line #L134 was not covered by tests
}
if (is.formula(sec.axis)) {
sec.axis <- sec_axis(sec.axis)
}
if (is.formula(sec.axis)) sec.axis <- sec_axis(sec.axis)
if (!is.sec_axis(sec.axis)) {
cli::cli_abort("Secondary axes must be specified using {.fn sec_axis}.")
}
Expand Down Expand Up @@ -205,7 +205,7 @@
self$trans(range)
},

mono_test = function(self, scale){
mono_test = function(self, scale) {
range <- scale$range$range

# Check if plot is empty
Expand All @@ -231,11 +231,11 @@
if (self$empty()) return()

# Test for monotonicity on unexpanded range
if (!scale$is_discrete()) {
if (scale$is_discrete()) {
breaks <- scale$map(self$breaks)
} else {
self$mono_test(scale)
breaks <- self$breaks
} else {
breaks <- scale$map(self$breaks)
}

# Get scale's original range before transformation
Expand All @@ -250,8 +250,8 @@
# the transformation is non-monotonic in the expansion. The split ensures
# the middle duplicated are kept
duplicates <- c(
!duplicated(full_range[seq_len(self$detail/2)], fromLast = TRUE),
!duplicated(full_range[-seq_len(self$detail/2)])
!duplicated(full_range[seq_len(self$detail / 2)], fromLast = TRUE),
!duplicated(full_range[-seq_len(self$detail / 2)])
)
old_range <- old_range[duplicates]
full_range <- full_range[duplicates]
Expand Down Expand Up @@ -318,13 +318,14 @@
# Temporary scale for the purpose of calling break_info()
create_scale = function(self, range, transformation = transform_identity(),
breaks = self$breaks) {
scale <- ggproto(NULL, ScaleContinuousPosition,
name = self$name,
breaks = breaks,
labels = self$labels,
limits = range,
expand = c(0, 0),
trans = transformation
scale <- ggproto(
NULL, ScaleContinuousPosition,
name = self$name,
breaks = breaks,
labels = self$labels,
limits = range,
expand = c(0, 0),
trans = transformation
)
scale$train(range)
scale
Expand Down
13 changes: 7 additions & 6 deletions R/bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
if (isTRUE((max_x - origin) / width > 1e6)) {
cli::cli_abort(c(
"The number of histogram bins must be less than 1,000,000.",
"i" = "Did you make {.arg binwidth} too small?"
i = "Did you make {.arg binwidth} too small?"
))
}
breaks <- seq(origin, max_x, width)
Expand Down Expand Up @@ -125,8 +125,9 @@ bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
}
}

bin_breaks_width(x_range, width, boundary = boundary, center = center,
closed = closed)
bin_breaks_width(
x_range, width, boundary = boundary, center = center, closed = closed
)
}


Expand All @@ -145,8 +146,7 @@ bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
weight[is.na(weight)] <- 0
}

bin_idx <- cut(x, bins$fuzzy, right = bins$right_closed,
include.lowest = TRUE)
bin_idx <- cut(x, bins$fuzzy, right = bins$right_closed, include.lowest = TRUE)
bin_count <- as.numeric(tapply(weight, bin_idx, sum, na.rm = TRUE))
bin_count[is.na(bin_count)] <- 0

Expand Down Expand Up @@ -175,7 +175,8 @@ bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
}

bin_out <- function(count = integer(0), x = numeric(0), width = numeric(0),
xmin = x - width / 2, xmax = x + width / 2) {
xmin = x - width / 2, xmax = x + width / 2) {

density <- count / width / sum(abs(count))

data_frame0(
Expand Down
8 changes: 3 additions & 5 deletions R/compat-plyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,14 @@ id <- function(.variables, drop = FALSE) {
if (n > 2^31) {
char_id <- inject(paste(!!!ids, sep = "\r"))
res <- match(char_id, unique0(char_id))
}
else {
} else {
combs <- c(1, cumprod(ndistinct[-p]))
mat <- inject(cbind(!!!ids))
res <- c((mat - 1L) %*% combs + 1L)
}
if (drop) {
id_var(res, drop = TRUE)
}
else {
} else {
res <- as.integer(res)
attr(res, "n") <- n
res
Expand Down Expand Up @@ -170,7 +168,7 @@ join_keys <- function(x, y, by) {
# round a number to a given precision
round_any <- function(x, accuracy, f = round) {
check_numeric(x)
f(x/accuracy) * accuracy
f(x / accuracy) * accuracy
}

#' Apply function to unique subsets of a data.frame
Expand Down
10 changes: 5 additions & 5 deletions R/coord-.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ Coord <- ggproto("Coord",
scale = scale_position[!is_sec]
)
opposite <- c(
"top" = "bottom", "bottom" = "top",
"left" = "right", "right" = "left"
top = "bottom", bottom = "top",
left = "right", right = "left"
)
guide_position[is_sec] <- Map(
function(sec, prim) sec %|W|% unname(opposite[prim]),
Expand Down Expand Up @@ -275,9 +275,9 @@ parse_coord_expand <- function(expand) {
}

# Utility function to check coord limits
check_coord_limits <- function(
limits, arg = caller_arg(limits), call = caller_env()
) {
check_coord_limits <- function(limits, arg = caller_arg(limits),
call = caller_env()) {

if (is.null(limits)) {
return(invisible(NULL))
}
Expand Down
2 changes: 1 addition & 1 deletion R/coord-cartesian-.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
left = panel_guides_grob(
panel_params$guides, position = "left",
theme = theme, labels = panel_params$draw_labels$left
),
),
right = panel_guides_grob(
panel_params$guides, position = "right",
theme = theme, labels = panel_params$draw_labels$right
Expand Down
Loading
Loading