Skip to content

Commit

Permalink
use more rlang
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Sep 7, 2023
1 parent 108b40b commit facc672
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ safe_eval <- function(expr, data) {
eval_tidy(expr, data),
error = function(e) numeric()
)
if (!is.function(value) &&
!is.environment(value) &&
!is.symbol(value) &&
if (!is_function(value) &&
!is_environment(value) &&
!is_symbol(value) &&
!is.language(value) &&
(length(value) == 1 || length(value) == nrow(data))) {
value
Expand All @@ -26,7 +26,7 @@ require_quo <- function(expr, name) {
}
}
require_stat <- function(x) {
if (is.call(x)) {
if (is_call(x)) {
if (identical(x[[1]], quote(stat)) || identical(x[[1]], quote(after_stat))) {
TRUE
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/animate.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ plot_dims <- function(plot, ref_frame) {
widths <- convertWidth(widths_rel, 'mm')
heights_rel <- frame$heights
heights <- convertHeight(heights_rel, 'mm')
if (is.list(widths)) { # New unit spec
if (is_list(widths)) { # New unit spec
null_widths <- vapply(unclass(widths), `[[`, numeric(1), 1L) == 0
null_heights <- vapply(unclass(heights), `[[`, numeric(1), 1L) == 0
} else {
Expand Down
4 changes: 2 additions & 2 deletions R/renderers.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ ffmpeg_renderer <- function(format = 'auto', ffmpeg = NULL, options = list(pix_f
"mp4"
}
}
if (is.list(options)) {
if (is_list(options)) {
if (is.null(names(options))) {
cli::cli_abort('{.arg options} must be a named list')
}
Expand Down Expand Up @@ -253,7 +253,7 @@ gif_file <- function(file) {
#' @export
print.gif_image <- function(x, ...) {
viewer <- getOption("viewer", utils::browseURL)
if (is.function(viewer) && length(x)) {
if (is_function(viewer) && length(x)) {
viewer(x)
} else {
invisible()
Expand Down
6 changes: 3 additions & 3 deletions R/scene.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Scene <- ggproto('Scene', NULL,
if (is.null(vp)) {
grid.draw(plot)
} else {
if (is.character(vp)) seekViewport(vp)
if (is_character(vp)) seekViewport(vp)
else pushViewport(vp)
grid.draw(plot)
upViewport()
Expand All @@ -145,7 +145,7 @@ Scene <- ggproto('Scene', NULL,
label_var$data <- plot$data
plot$plot$labels <- lapply(plot$plot$labels, function(label) {
orig_call <- FALSE
if (is.call(label)) {
if (is_call(label)) {
orig_call <- TRUE
label <- list(label)
}
Expand All @@ -159,7 +159,7 @@ Scene <- ggproto('Scene', NULL,
})
if (orig_call) {
new_label[[1]]
} else if (is.expression(label)) {
} else if (is_expression(label)) {
as.expression(new_label)
} else {
unlist(new_label)
Expand Down
4 changes: 2 additions & 2 deletions R/shadow-wake.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
#' }
#'
shadow_wake <- function(wake_length, size = TRUE, alpha = TRUE, colour = NULL, fill = NULL, falloff = 'cubic-in', wrap = TRUE, exclude_layer = NULL, exclude_phase = c('enter', 'exit')) {
if (is.logical(size)) size <- if (size) 0 else NULL
if (is.logical(alpha)) alpha <- if (alpha) 0 else NULL
if (is_logical(size)) size <- if (size) 0 else NULL
if (is_logical(alpha)) alpha <- if (alpha) 0 else NULL

ggproto(NULL, ShadowWake,
exclude_layer = exclude_layer,
Expand Down
2 changes: 1 addition & 1 deletion R/transition-filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ assign_filters <- function(data, filters, after = FALSE, row_vars = NULL) {
if (!do_filter[i]) return(rep(FALSE, nrow(d)))
filter <- safe_eval(filters[[i]], d)
filter <- filter %||% rep(TRUE, nrow(d))
if (!is.logical(filter)) cli::cli_abort('Filters must return a logical vector')
if (!is_logical(filter)) cli::cli_abort('Filters must return a logical vector')
filter
}))
if (all(row_filter)) return(numeric(0))
Expand Down
2 changes: 1 addition & 1 deletion R/transition-layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ NULL
#' exit_fade() + exit_shrink()
#'
transition_layers <- function(layer_length = 1, transition_length = 1, keep_layers = TRUE, from_blank = TRUE, layer_order = NULL, layer_names = NULL) {
if (is.logical(keep_layers)) keep_layers <- if (keep_layers) Inf else 0L
if (is_logical(keep_layers)) keep_layers <- if (keep_layers) Inf else 0L
ggproto(NULL, TransitionLayers,
params = list(
layer_length = layer_length,
Expand Down
4 changes: 2 additions & 2 deletions R/view-.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ View <- ggproto('View', NULL,
plot
},
reset_limits = function(self, plot, xlim, ylim) {
if (is.logical(self$fixed_lim$x)) {
if (is_logical(self$fixed_lim$x)) {
if (self$fixed_lim$x) xlim <- plot$layout$coord$limits$x
} else {
xlim[!is.na(self$fixed_lim$x)] <- self$fixed_lim$x[!is.na(self$fixed_lim$x)]
}
if (is.logical(self$fixed_lim$y)) {
if (is_logical(self$fixed_lim$y)) {
if (self$fixed_lim$y) ylim <- plot$layout$coord$limits$y
} else {
ylim[!is.na(self$fixed_lim$y)] <- self$fixed_lim$y[!is.na(self$fixed_lim$y)]
Expand Down
2 changes: 1 addition & 1 deletion man/transition_reveal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit facc672

Please sign in to comment.