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

before CRAN #17

Merged
merged 29 commits into from
Nov 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0751d7d
before cran
Polkas Nov 18, 2024
70b593f
title case title
Polkas Nov 19, 2024
00bc425
add quote for ggplot2 in DESCRIPTION
Polkas Nov 20, 2024
984510b
cran comments and standalone
Polkas Nov 21, 2024
de6472d
cran comments and standalone
Polkas Nov 21, 2024
b7713ed
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
215a7ad
prefix standalone
Polkas Nov 21, 2024
9e8fdfd
depends
Polkas Nov 21, 2024
b90cf6f
update
Polkas Nov 21, 2024
83e31d0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
e135345
Update README.md
Polkas Nov 21, 2024
b3f0088
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
9f083ff
add import
Polkas Nov 21, 2024
c5a4145
edit docs
Polkas Nov 21, 2024
c34c728
improve
Polkas Nov 21, 2024
2fd4a2f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
9f23561
improve
Polkas Nov 21, 2024
b9207ff
update
Polkas Nov 21, 2024
e6aaf52
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
7ecb7c0
update
Polkas Nov 21, 2024
50fb7a2
dont run styler
Polkas Nov 21, 2024
0037c16
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
5e0eec6
ggcall_example
Polkas Nov 21, 2024
aeb41f2
clean check
Polkas Nov 21, 2024
1a990d4
clean check
Polkas Nov 21, 2024
8444f50
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
8261d71
edit NEWS
Polkas Nov 21, 2024
178193f
edit NEWS
Polkas Nov 21, 2024
54726c4
edit NEWS
Polkas Nov 21, 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
Prev Previous commit
Next Next commit
cran comments and standalone
Polkas committed Nov 21, 2024
commit 984510bfc382064832a612f19bf5ce9998f1c4cf
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -11,13 +11,14 @@ Maintainer: Maciej Nasinski <nasinski.maciej@gmail.com>
Description:
Enhance 'ggplot2' with the ability to extract the code used to create a 'ggplot2' object, even when it is generated within a function.
This feature aids in understanding, replicating, and modifying complex 'ggplot2' visualizations produced in functional workflows.
URL: https://github.com/Polkas/ggcall, https://polkas.github.io/ggcall/
BugReports: https://github.com/Polkas/ggcall/issues
License: Apache License (>= 2)
Encoding: UTF-8
LazyData: true
Depends:
ggplot2
Suggests:
backports,
knitr,
patchwork,
rmarkdown,
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ggcall v0.3.2
# ggcall v0.3.3

* First CRAN release.
* Support usethis standalone, usethis::use_standalone can be used on ggcall to not depend on the ggcall package rather copy paste file to your package.

# ggcall v0.3.0

23 changes: 22 additions & 1 deletion R/ggcall.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# ---
# repo: polkas/ggcall
# file: ggcall.R
# last-updated: 2024-11-21
# license: https://unlicense.org
# imports: ggplot2
# ---
#
# This file provides a minimal shim to provide a ggcall functionality on top of
# ggplot2.
#
# ## Changelog
#

# nocov start

#' Enhanced `ggplot` Function with History Tracking
#'
#' Overrides the default `ggplot` function from the ggplot2 package, adding the
@@ -112,7 +128,10 @@ ggplot <- function(...) {
#' }
#' plot_call <- ggcall(func(mtcars, "wt", "mpg"))
#' # Optionally: Style the code with styler
#' styler::style_text(backports:::deparse1(plot_call))
#' # deparse1 is recommended and available in R>=4.0.0
#' styler::style_text(
#' paste(deparse(plot_call, 500), collapse = " ")
#' )
#'
#' @export
#'
@@ -309,3 +328,5 @@ extract_names <- function(expr) {

return(character())
}

# nocov end
19 changes: 19 additions & 0 deletions R/patchwork.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# ---
# repo: polkas/ggcall
# file: patchwork
# last-updated: 2024-11-21
# license: https://unlicense.org
# dependencies: ggcall.R
# imports: [ggplot2, patchwork]
# ---
#
# This file provides a minimal shim to provide a ggcall functionality on top of
# ggplot2. Additionally patchwork operators are supported.
#
# ## Changelog
#

# nocov start

#' @keywords internal
patch_operator_base <- function(e1, e2, operator, class) {
if (!requireNamespace("patchwork", quietly = TRUE)) {
@@ -38,3 +55,5 @@ patch_operator_base <- function(e1, e2, operator, class) {
"&.ggcall" <- function(e1, e2) {
patch_operator_base(e1, e2, "&", "gg")
}

# nocov end
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -73,7 +73,11 @@ plot_call
# attr(,"ggcall_env")
# <environment: abcd1234>

styler::style_text(backports:::deparse1(plot_call))
# Optionally: Style the code with styler
# install.packages("styler")
styler::style_text(
paste(deparse(plot_call), collapse = "\n")
)

# Optionally: add assignments to call
plot_call_with_assignments <- ggcall_add_assignments(plot_call)
5 changes: 4 additions & 1 deletion man/ggcall.Rd

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

5 changes: 4 additions & 1 deletion tests/testthat/test_ggcall.R
Original file line number Diff line number Diff line change
@@ -39,7 +39,10 @@ test_that("ggcall incorrect input", {
test_that("ggcall returns correct call", {
plot_call1 <- ggcall(func("wt", "mpg"))
plot_call2 <- ggcall(funy())
testthat::expect_identical(backports:::deparse1(plot_call1), backports:::deparse1(plot_call2))
testthat::expect_identical(
paste(deparse(plot_call1), collapse = "\n"),
paste(deparse(plot_call2), collapse = "\n")
)
})

# nolint start
18 changes: 9 additions & 9 deletions tests/testthat/test_ggcall_with_assignments.R
Original file line number Diff line number Diff line change
@@ -23,21 +23,21 @@ test_that("ggcall_add_assignments correctly adds assignments", {
result_call <- ggcall_add_assignments(plot_call)

expect_true(inherits(result_call, "ggcall_code"))
expect_true(grepl("data <-", backports:::deparse1(result_call)))
expect_true(grepl("x <-", backports:::deparse1(result_call)))
expect_true(grepl("y <-", backports:::deparse1(result_call)))
expect_true(grepl('data <- ggcall_env\\(plot_call\\)\\[\\[\\"data\\"\\]\\]', backports:::deparse1(result_call)))
expect_true(grepl('x <- \\"wt\\"', backports:::deparse1(result_call)))
expect_true(grepl('y <- \\"mpg\\"', backports:::deparse1(result_call)))
expect_true(grepl("ggplot\\(data", backports:::deparse1(result_call)))
expect_true(grepl("data <-", paste(deparse(result_call), collapse = "\n")))
expect_true(grepl("x <-", paste(deparse(result_call), collapse = "\n")))
expect_true(grepl("y <-", paste(deparse(result_call), collapse = "\n")))
expect_true(grepl('data <- ggcall_env\\(plot_call\\)\\[\\[\\"data\\"\\]\\]', paste(deparse(result_call), collapse = "\n")))
expect_true(grepl('x <- \\"wt\\"', paste(deparse(result_call), collapse = "\n")))
expect_true(grepl('y <- \\"mpg\\"', paste(deparse(result_call), collapse = "\n")))
expect_true(grepl("ggplot\\(data", paste(deparse(result_call), collapse = "\n")))
expect_silent(eval(result_call))
})


test_that("ggcall_add_assignments incorrectly adds assignments", {
result_call <- ggcall_add_assignments(plot_call, vars = "x")
expect_true(grepl("x <-", backports:::deparse1(result_call)))
expect_false(grepl("data <-", backports:::deparse1(result_call)))
expect_true(grepl("x <-", paste(deparse(result_call), collapse = "\n")))
expect_false(grepl("data <-", paste(deparse(result_call), collapse = "\n")))
expect_error(eval(result_call))
})

113 changes: 64 additions & 49 deletions tests/testthat/test_patchwork.R
Original file line number Diff line number Diff line change
@@ -9,15 +9,18 @@ p4 <- ggplot(mtcars) + geom_bar(aes(carb))
test_that("patchwork + operator pure", {
expect_error(p1 + p2 + p3, NA)
gcall <- ggcall(p1 + p2 + p3)
decall <- backports:::deparse1(gcall)
decall <- paste(deparse(gcall), collapse = "\n")
expect_identical(
decall,
backports:::deparse1(
quote(
ggplot(mtcars) + geom_point(aes(mpg, disp)) +
(ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))) +
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl))
)
paste(
deparse(
quote(
ggplot(mtcars) + geom_point(aes(mpg, disp)) +
(ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))) +
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl))
)
),
collapse = "\n"
)
)
expect_true(is.ggplot(eval_ggcall(gcall)))
@@ -26,19 +29,22 @@ test_that("patchwork + operator pure", {
test_that("patchwork operators - direct pure", {
expect_error(p1 | p2 - p3 * p4 + p1 & p2 | p3, NA)
gcall <- ggcall(p1 | p2 - p3 * p4 + p1 & p2 | p3)
decall <- backports:::deparse1(gcall)
decall <- paste(deparse(gcall), collapse = "\n")
expect_identical(
decall,
backports:::deparse1(
quote(
ggplot(mtcars) + geom_point(aes(mpg, disp)) |
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) -
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)) *
(ggplot(mtcars) + geom_bar(aes(carb))) +
(ggplot(mtcars) + geom_point(aes(mpg, disp))) &
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) |
ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)
)
paste(
deparse(
quote(
ggplot(mtcars) + geom_point(aes(mpg, disp)) |
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) -
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)) *
(ggplot(mtcars) + geom_bar(aes(carb))) +
(ggplot(mtcars) + geom_point(aes(mpg, disp))) &
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) |
ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)
)
),
collapse = "\n"
)
)
expect_true(is.ggplot(eval_ggcall(gcall)))
@@ -49,16 +55,19 @@ library(patchwork)
test_that("patchwork + operator with patchwork", {
expect_error(p1 + p2 + p3 + plot_layout(ncol = 1), NA)
gcall <- ggcall(p1 + p2 + p3 + plot_layout(ncol = 1))
decall <- backports:::deparse1(gcall)
decall <- paste(deparse(gcall), collapse = "\n")
expect_identical(
decall,
backports:::deparse1(
quote(
ggplot(mtcars) + geom_point(aes(mpg, disp)) +
(ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))) +
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)) +
plot_layout(ncol = 1)
)
paste(
deparse(
quote(
ggplot(mtcars) + geom_point(aes(mpg, disp)) +
(ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))) +
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)) +
plot_layout(ncol = 1)
)
),
collapse = "\n"
)
)
expect_true(is.ggplot(eval_ggcall(gcall)))
@@ -67,19 +76,22 @@ test_that("patchwork + operator with patchwork", {
test_that("patchwork operators - direct", {
expect_error(p1 | p2 - p3 * p4 + p1 & p2 | p3, NA)
gcall <- ggcall(p1 | p2 - p3 * p4 + p1 & p2 | p3)
decall <- backports:::deparse1(gcall)
decall <- paste(deparse(gcall), collapse = "\n")
expect_identical(
decall,
backports:::deparse1(
quote(
ggplot(mtcars) + geom_point(aes(mpg, disp)) |
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) -
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)) *
(ggplot(mtcars) + geom_bar(aes(carb))) +
(ggplot(mtcars) + geom_point(aes(mpg, disp))) &
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) |
ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)
)
paste(
deparse(
quote(
ggplot(mtcars) + geom_point(aes(mpg, disp)) |
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) -
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)) *
(ggplot(mtcars) + geom_bar(aes(carb))) +
(ggplot(mtcars) + geom_point(aes(mpg, disp))) &
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) |
ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)
)
),
collapse = "\n"
)
)
expect_true(is.ggplot(eval_ggcall(gcall)))
@@ -98,21 +110,24 @@ test_that("patchwork operators - internal", {

gcall <- ggcall(funy())

decall <- backports:::deparse1(gcall)
decall <- paste(deparse(gcall), collapse = "\n")

expect_identical(
decall,
backports:::deparse1(
quote(
ggplot(mtcars) + geom_point(aes(mpg, disp)) |
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) -
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)) *
(ggplot(mtcars) + geom_bar(aes(carb))) +
(ggplot(mtcars) + geom_point(aes(mpg, disp))) &
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) |
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)) /
(ggplot(mtcars) + geom_point(aes(mpg, disp)))
)
paste(
deparse(
quote(
ggplot(mtcars) + geom_point(aes(mpg, disp)) |
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) -
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)) *
(ggplot(mtcars) + geom_bar(aes(carb))) +
(ggplot(mtcars) + geom_point(aes(mpg, disp))) &
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) |
(ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)) /
(ggplot(mtcars) + geom_point(aes(mpg, disp)))
)
),
collapse = "\n"
)
)
expect_true(is.ggplot(eval_ggcall(gcall)))
10 changes: 8 additions & 2 deletions vignettes/ggcall.Rmd
Original file line number Diff line number Diff line change
@@ -79,7 +79,11 @@ plot_call
# attr(,"ggcall_env")
# <environment: abcd1234>

styler::style_text(backports:::deparse1(plot_call))
# Optionally: Style the code with styler
# install.packages("styler")
styler::style_text(
paste(deparse(plot_call_with_assignments), collapse = "\n")
)

# Optionally: add assignments to call
plot_call_with_assignments <- ggcall_add_assignments(plot_call)
@@ -148,7 +152,9 @@ plot_call

# Optionally: Style the code with styler
# install.packages("styler")
styler::style_text(backports:::deparse1(plot_call))
styler::style_text(
paste(deparse(plot_call), collapse = "\n")
)
# ggplot(data, aes(x = .data[[x]], y = .data[[y]])) +
# geom_point(alpha = 0.4) +
# facet_grid(~gear) +