Skip to content

Commit

Permalink
move data argument to the first
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Dec 8, 2024
1 parent 4bcda06 commit d390ae3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ S3method(free_border,free_lab)
S3method(free_border,ggplot)
S3method(free_gg,default)
S3method(free_gg,ggplot)
S3method(free_gg,uneval)
S3method(free_guide,alignpatches)
S3method(free_guide,free_guide)
S3method(free_guide,ggplot)
Expand Down
18 changes: 13 additions & 5 deletions R/plot-free-gg.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#' ggheatmap(matrix(rnorm(56), nrow = 7)) +
#' anno_top() +
#' align_dendro() +
#' ggfree(aes(wt, mpg), data = mtcars) +
#' ggfree(mtcars, aes(wt, mpg)) +
#' geom_point()
#' @export
free_gg <- function(..., data = waiver(), size = NULL, active = NULL) {
free_gg <- function(data = waiver(), ..., size = NULL, active = NULL) {
rlang::check_dots_used()
UseMethod("free_gg", data)
}
Expand All @@ -36,8 +36,8 @@ ggfree <- free_gg
#' @importFrom ggplot2 ggplot
#' @export
#' @rdname free_gg
free_gg.default <- function(mapping = aes(), ...,
data = waiver(), size = NULL, active = NULL) {
free_gg.default <- function(data = waiver(), mapping = aes(), ...,
size = NULL, active = NULL) {
data <- fortify_data_frame(data = data, ...)
new_free_gg(
plot = ggplot(data = NULL, mapping = mapping),
Expand All @@ -47,9 +47,17 @@ free_gg.default <- function(mapping = aes(), ...,
)
}

#' @export
free_gg.uneval <- function(data = waiver(), ...) {
cli_abort(c(
"{.arg data} cannot be {.obj_type_friendly {data}}",
"i" = "Have you misspelled the {.arg data} argument in {.fn ggalign}"
))
}

#' @export
#' @rdname free_gg
free_gg.ggplot <- function(..., data = waiver(), size = NULL, active = NULL) {
free_gg.ggplot <- function(data = waiver(), ..., size = NULL, active = NULL) {
plot <- data
# In ggplot2, `waiver()` was regard to no data
data <- .subset2(plot, "data") %|w|% NULL
Expand Down
12 changes: 6 additions & 6 deletions man/free_gg.Rd

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

0 comments on commit d390ae3

Please sign in to comment.