Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ visual_test
^vignettes/articles$
^CRAN-SUBMISSION$
^docs$
^[.]?air[.]toml$
^\.vscode$
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"Posit.air-vscode"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"[r]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "Posit.air-vscode"
},
"[quarto]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "quarto.quarto"
}
}
32 changes: 25 additions & 7 deletions R/aes-evaluation.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ from_theme <- function(x) {
stage <- function(start = NULL, after_stat = NULL, after_scale = NULL) {
start
}
stage_calculated <- function(start = NULL, after_stat = NULL, after_scale = NULL) {
stage_calculated <- function(
start = NULL,
after_stat = NULL,
after_scale = NULL
) {
after_stat
}
stage_scaled <- function(start = NULL, after_stat = NULL, after_scale = NULL) {
Expand Down Expand Up @@ -304,26 +308,42 @@ strip_dots <- function(expr, env, strip_pronoun = FALSE) {
} else if (is_quosure(expr)) {
# strip dots from quosure and reconstruct the quosure
new_quosure(
strip_dots(quo_get_expr(expr), env = quo_get_env(expr), strip_pronoun = strip_pronoun),
strip_dots(
quo_get_expr(expr),
env = quo_get_env(expr),
strip_pronoun = strip_pronoun
),
quo_get_env(expr)
)
} else if (is.call(expr)) {
if (strip_pronoun && is_call(expr, "$") && is_symbol(expr[[2]], ".data")) {
strip_dots(expr[[3]], env, strip_pronoun = strip_pronoun)
} else if (strip_pronoun && is_call(expr, "[[") && is_symbol(expr[[2]], ".data")) {
} else if (
strip_pronoun && is_call(expr, "[[") && is_symbol(expr[[2]], ".data")
) {
tryCatch(
sym(eval(expr[[3]], env)),
error = function(e) expr[[3]]
)
} else if (is_call(expr, "stat")) {
strip_dots(expr[[2]], env, strip_pronoun = strip_pronoun)
} else {
expr[-1] <- lapply(expr[-1], strip_dots, env = env, strip_pronoun = strip_pronoun)
expr[-1] <- lapply(
expr[-1],
strip_dots,
env = env,
strip_pronoun = strip_pronoun
)
expr
}
} else if (is.pairlist(expr)) {
# In the unlikely event of an anonymous function
as.pairlist(lapply(expr, strip_dots, env = env, strip_pronoun = strip_pronoun))
as.pairlist(lapply(
expr,
strip_dots,
env = env,
strip_pronoun = strip_pronoun
))
} else if (is.list(expr)) {
# For list of aesthetics
lapply(expr, strip_dots, env = env, strip_pronoun = strip_pronoun)
Expand Down Expand Up @@ -367,7 +387,6 @@ make_labels <- function(mapping) {
}

eval_aesthetics <- function(aesthetics, data, mask = NULL) {

env <- child_env(base_env())

# Here we mask functions, often to replace `stage()` with context appropriate
Expand Down Expand Up @@ -400,4 +419,3 @@ mask_function <- function(x, mask) {
}
}
}

51 changes: 38 additions & 13 deletions R/aes.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ local({
cat("<empty>\n")
} else {
values <- vapply(x, quo_label, character(1))
bullets <- paste0("* ", format(paste0("`", names(x), "`")), " -> ", values, "\n")
bullets <- paste0(
"* ",
format(paste0("`", names(x), "`")),
" -> ",
values,
"\n"
)

cat(bullets, sep = "")
}
Expand Down Expand Up @@ -195,7 +201,9 @@ rename_aes <- function(x) {
names(x) <- standardise_aes_names(names(x))
duplicated_names <- names(x)[duplicated(names(x))]
if (length(duplicated_names) > 0L) {
cli::cli_warn("Duplicated aesthetics after name standardisation: {.field {unique0(duplicated_names)}}")
cli::cli_warn(
"Duplicated aesthetics after name standardisation: {.field {unique0(duplicated_names)}}"
)
}
x
}
Expand Down Expand Up @@ -289,8 +297,12 @@ aes_ <- function(x, y, ...) {
details = "Please use tidy evaluation idioms with `aes()`"
)
mapping <- list(...)
if (!missing(x)) mapping["x"] <- list(x)
if (!missing(y)) mapping["y"] <- list(y)
if (!missing(x)) {
mapping["x"] <- list(x)
}
if (!missing(y)) {
mapping["y"] <- list(y)
}

caller_env <- parent.frame()

Expand All @@ -300,7 +312,9 @@ aes_ <- function(x, y, ...) {
} else if (is.null(x) || is.call(x) || is.name(x) || is.atomic(x)) {
new_aesthetic(x, caller_env)
} else {
cli::cli_abort("Aesthetic must be a one-sided formula, call, name, or constant.")
cli::cli_abort(
"Aesthetic must be a one-sided formula, call, name, or constant."
)
}
}
mapping <- lapply(mapping, as_quosure_aes)
Expand All @@ -319,8 +333,12 @@ aes_string <- function(x, y, ...) {
)
)
mapping <- list(...)
if (!missing(x)) mapping["x"] <- list(x)
if (!missing(y)) mapping["y"] <- list(y)
if (!missing(x)) {
mapping["x"] <- list(x)
}
if (!missing(y)) {
mapping["y"] <- list(y)
}

caller_env <- parent.frame()
mapping <- lapply(mapping, function(x) {
Expand Down Expand Up @@ -351,7 +369,9 @@ aes_all <- function(vars) {

# Quosure the symbols in the empty environment because they can only
# refer to the data mask
x <- class_mapping(lapply(vars, function(x) new_quosure(as.name(x), emptyenv())))
x <- class_mapping(lapply(vars, function(x) {
new_quosure(as.name(x), emptyenv())
}))
class(x) <- union("unlabelled", class(x))
x
}
Expand Down Expand Up @@ -423,10 +443,13 @@ extract_target_is_likely_data <- function(x, data, env) {
return(FALSE)
}

tryCatch({
data_eval <- eval_tidy(x[[2]], data, env)
identical(unrowname(data_eval), unrowname(data))
}, error = function(err) FALSE)
tryCatch(
{
data_eval <- eval_tidy(x[[2]], data, env)
identical(unrowname(data_eval), unrowname(data))
},
error = function(err) FALSE
)
}

# Takes a quosure and returns a named list of quosures, expanding
Expand All @@ -438,7 +461,9 @@ arg_enquos <- function(name, frame = caller_env()) {
expr <- quo_get_expr(quo)

is_triple_bang <- !is_missing(expr) &&
is_bang(expr) && is_bang(expr[[2]]) && is_bang(expr[[c(2, 2)]])
is_bang(expr) &&
is_bang(expr[[2]]) &&
is_bang(expr[[c(2, 2)]])
if (is_triple_bang) {
# Evaluate `!!!` operand and create a list of quosures
env <- quo_get_env(quo)
Expand Down
74 changes: 42 additions & 32 deletions R/all-classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class_guides <- S7::new_S3_class("Guides")
#' @export
#' @format NULL
#' @usage NULL
class_guide <- S7::new_S3_class("Guide")
class_guide <- S7::new_S3_class("Guide")

#' @rdname class_definitions
#' @section ggproto classes:
Expand All @@ -108,7 +108,7 @@ class_guide <- S7::new_S3_class("Guide")
#' @export
#' @format NULL
#' @usage NULL
class_coord <- S7::new_S3_class("Coord")
class_coord <- S7::new_S3_class("Coord")


#' @rdname class_definitions
Expand All @@ -118,7 +118,7 @@ class_coord <- S7::new_S3_class("Coord")
#' @export
#' @format NULL
#' @usage NULL
class_facet <- S7::new_S3_class("Facet")
class_facet <- S7::new_S3_class("Facet")

#' @rdname class_definitions
#' @section ggproto classes:
Expand All @@ -128,7 +128,7 @@ class_facet <- S7::new_S3_class("Facet")
#' @export
#' @format NULL
#' @usage NULL
class_layer <- S7::new_S3_class("Layer")
class_layer <- S7::new_S3_class("Layer")

#' @rdname class_definitions
#' @section ggproto classes:
Expand Down Expand Up @@ -213,12 +213,18 @@ class_derive <- S7::new_S3_class("derive")
#' @keywords internal
#' @export
class_theme <- S7::new_class(
"theme", class_S3_gg,
"theme",
class_S3_gg,
properties = list(
complete = S7::class_logical,
validate = S7::class_logical
),
constructor = function(elements = list(), ..., complete = FALSE, validate = TRUE) {
constructor = function(
elements = list(),
...,
complete = FALSE,
validate = TRUE
) {
warn_dots_empty()
S7::new_object(
elements,
Expand Down Expand Up @@ -246,7 +252,8 @@ class_theme <- S7::new_class(
#' @keywords internal
#' @export
class_labels <- S7::new_class(
"labels", parent = class_S3_gg,
"labels",
parent = class_S3_gg,
constructor = function(labels = list(), ...) {
warn_dots_empty()
S7::new_object(labels)
Expand Down Expand Up @@ -282,7 +289,8 @@ class_labels <- S7::new_class(
#' @keywords internal
#' @export
class_mapping <- S7::new_class(
"mapping", parent = class_S3_gg,
"mapping",
parent = class_S3_gg,
constructor = function(x = list(), ..., env = globalenv()) {
warn_dots_empty()
check_object(x, is.list, "a {.cls list}")
Expand Down Expand Up @@ -320,19 +328,20 @@ class_mapping <- S7::new_class(
#' @keywords internal
#' @export
class_ggplot <- S7::new_class(
name = "ggplot", parent = class_gg,
name = "ggplot",
parent = class_gg,
properties = list(
data = S7::class_any,
layers = S7::class_list,
scales = class_scales_list,
guides = class_guides,
data = S7::class_any,
layers = S7::class_list,
scales = class_scales_list,
guides = class_guides,
mapping = class_mapping,
theme = class_theme,
theme = class_theme,
coordinates = class_coord,
facet = class_facet,
layout = class_layout,
labels = class_labels,
meta = S7::class_list,
facet = class_facet,
layout = class_layout,
labels = class_labels,
meta = S7::class_list,
plot_env = S7::class_environment
),
constructor = function(
Expand All @@ -353,18 +362,18 @@ class_ggplot <- S7::new_class(
warn_dots_empty()
S7::new_object(
S7::S7_object(),
data = data,
layers = layers,
scales = scales %||% scales_list(),
guides = guides %||% guides_list(),
mapping = mapping,
theme = theme %||% theme(),
data = data,
layers = layers,
scales = scales %||% scales_list(),
guides = guides %||% guides_list(),
mapping = mapping,
theme = theme %||% theme(),
coordinates = coordinates,
facet = facet,
layout = layout %||% ggproto(NULL, Layout),
labels = labels,
meta = meta,
plot_env = plot_env
facet = facet,
layout = layout %||% ggproto(NULL, Layout),
labels = labels,
meta = meta,
plot_env = plot_env
)
}
)
Expand All @@ -387,11 +396,12 @@ class_ggplot <- S7::new_class(
#' @keywords internal
#' @export
class_ggplot_built <- S7::new_class(
"ggplot_built", parent = class_gg,
"ggplot_built",
parent = class_gg,
properties = list(
data = S7::class_list,
data = S7::class_list,
layout = class_layout,
plot = class_ggplot
plot = class_ggplot
),
constructor = function(..., data = NULL, layout = NULL, plot = NULL) {
warn_dots_empty()
Expand Down
19 changes: 15 additions & 4 deletions R/annotation-borders.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,24 @@
#' scale_size_area() +
#' coord_quickmap()
#' }
annotation_borders <- function(database = "world", regions = ".", fill = NA,
colour = "grey50", xlim = NULL, ylim = NULL, ...) {
annotation_borders <- function(
database = "world",
regions = ".",
fill = NA,
colour = "grey50",
xlim = NULL,
ylim = NULL,
...
) {
df <- map_data(database, regions, xlim = xlim, ylim = ylim)
annotate(
geom = "polygon",
x = df$long, y = df$lat, group = df$group,
fill = fill, colour = colour, ...
x = df$long,
y = df$lat,
group = df$group,
fill = fill,
colour = colour,
...
)
}

Expand Down
Loading
Loading