Skip to content
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

feat: support trailing commas everywhere #287

Merged
merged 1 commit into from
Feb 27, 2024
Merged
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ importFrom(rlang,is_scalar_double)
importFrom(rlang,is_scalar_integer)
importFrom(rlang,is_scalar_logical)
importFrom(rlang,is_string)
importFrom(rlang,list2)
importFrom(stats,ave)
importFrom(stats,complete.cases)
importFrom(systemfonts,match_font)
Expand Down
6 changes: 4 additions & 2 deletions R/element_interactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ element_text_interactive <- function(...)
element_interactive(element_text, ...)

#' Calls a base ggplot2 element function and returns an interactive element.
#' @importFrom rlang list2
#' @noRd
element_interactive <- function(element_func,
...,
extra_interactive_params = NULL) {
args <- list(...)
args <- list2(...)
# We need to get the interactive parameters from the arguments and remove them
ipar <- get_default_ipar(extra_interactive_params)
ip <- get_interactive_attrs(args, ipar = ipar)
Expand Down Expand Up @@ -70,6 +71,7 @@ element_interactive <- function(element_func,
#' @param label The text for the label (scalar character)
#' @param ... any of the [interactive_parameters].
#' @return an interactive label object
#' @inheritParams rlang list2
#' @export
#' @examples
#' library(ggplot2)
Expand All @@ -91,7 +93,7 @@ element_interactive <- function(element_func,
#' if( interactive() ) print(x)
#' @seealso [interactive_parameters], [labeller_interactive()]
label_interactive <- function(label, ...) {
dots <- list(...)
dots <- list2(...)
ipar <- get_default_ipar(dots$extra_interactive_params)
ip <- get_interactive_attrs(dots, ipar = ipar)
structure(
Expand Down
3 changes: 2 additions & 1 deletion R/geom_boxplot_interactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ StatInteractiveBoxplot <- ggproto(
#' # add interactive boxplot -------
#' @example examples/geom_boxplot_interactive.R
#' @seealso [girafe()]
#' @importFrom rlang list2
#' @export
geom_boxplot_interactive <- function(...) {
args <- list(...)
args <- list2(...)
if ("extra_interactive_params" %in% names(args)) {
args$extra_interactive_params <- c(args$extra_interactive_params, outlier_ipar)
} else {
Expand Down
3 changes: 2 additions & 1 deletion R/girafe_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,14 @@ opts_sizing <- function(rescale = TRUE, width = 1){
#' }
#' @export
#' @seealso [girafe()], [girafe_css()], [girafe_css_bicolor()]
#' @importFrom rlang list2
#' @family girafe animation options
girafe_options <- function(x, ...){
if(!inherits(x, "girafe")) {
abort("`x` must be a girafe object", call = NULL)
}

args <- list(...)
args <- list2(...)
x$x$settings <- merge_options(x$x$settings, args)
x$sizingPolicy <- merge_sizing_policy(x$sizingPolicy, args)
x
Expand Down
3 changes: 2 additions & 1 deletion R/guide_interactive.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#' Calls a base guide function and returns an interactive guide.
#' @noRd
#' @importFrom rlang list2
guide_interactive <- function(guide_func,
...,
interactive_guide = NULL) {
args <- list(...)
args <- list2(...)
# Call default guide function
if (is.function(guide_func)) {
guide <- do.call(guide_func, args)
Expand Down
4 changes: 2 additions & 2 deletions R/labeller_interactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
#' # use interactive labeller
#' @example examples/labeller_interactive.R
#' @seealso [labeller()], [label_interactive()], [labellers]
#' @importFrom rlang eval_tidy
#' @importFrom rlang eval_tidy list2
#' @importFrom purrr imap
labeller_interactive <- function(.mapping = NULL, ...) {
# get interactive aesthetics, plus a label parameter
dots <- list(...)
dots <- list2(...)
extra_interactive_params <- c(dots$extra_interactive_params, "label")
ipar <- get_default_ipar(extra_interactive_params)
ip <- get_interactive_attrs(.mapping, ipar = ipar)
Expand Down
3 changes: 2 additions & 1 deletion R/layer_interactive.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#' Calls a base ggplot2 geom/layer function and replaces the geom param
#' so that it points to the analogous interactive geom.
#' @importFrom purrr detect_index
#' @importFrom rlang list2
#' @noRd
layer_interactive <- function(layer_func,
...,
interactive_geom = NULL,
extra_interactive_params = NULL) {
args <- list(...)
args <- list2(...)
# we need to temporarily remove the interactive aesthetics if they exist
# we could use check.aes = FALSE and check.param = FALSE but no fun there
interactive_mapping <- NULL
Expand Down
4 changes: 2 additions & 2 deletions R/scale_interactive.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#' Calls a base scale function and returns an interactive scale.
#' @noRd
#' @importFrom rlang inherits_any
#' @importFrom rlang inherits_any list2
scale_interactive <- function(scale_func,
...,
extra_interactive_params = NULL) {
args <- list(...)
args <- list2(...)
# We need to get the interactive parameters from the arguments and remove them
ipar <- get_default_ipar(extra_interactive_params)
interactive_params <- get_interactive_attrs(args, ipar = ipar)
Expand Down
48 changes: 48 additions & 0 deletions inst/tinytest/test-trailing-comma.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
library(tinytest)
library(ggiraph)
library(ggplot2)


# Trailing comma allowed ----
{
p <- diamonds |>
ggplot() +
geom_bar_interactive(
mapping = aes(
x = color,
fill = color,
),
) +
scale_fill_discrete_interactive(
guide = guide_legend_interactive(
title = "Color",
position = "bottom",
),
) +
facet_wrap_interactive(vars(cut), ) +
annotate_interactive("text", x = "E", y = 1, label = "E", color = "red", vjust = "bottom", ) +
labs(
title = label_interactive("Title",)
) +
theme(
plot.title = element_text_interactive(tooltip = "Plot title",)
)

g <- girafe(code = print(p))
expect_inherits(g, c("ggiraph", "girafe", "htmlwidget"))

}

# girafe, trailing comma ----
{
g <- girafe(ggobj = ggplot(),)
expect_inherits(g, c("girafe", "htmlwidget"))
}

# girafe_options, trailing comma ----
{
g <- girafe({
NULL
})
expect_identical(girafe_options(g, ), g, info = "no options set")
}
Loading