Skip to content

Commit

Permalink
Add gradethis_equal() method for ggplot objects (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: rossellhayes <[email protected]>
  • Loading branch information
rossellhayes and rossellhayes authored May 8, 2023
1 parent b784777 commit 155f77d
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 18 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
- {os: windows-latest, r: '3.6'}

# Use older ubuntu to maximise backward compatibility
- {os: ubuntu-18.04, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-18.04, r: 'release'}
- {os: ubuntu-18.04, r: 'oldrel-1'}
- {os: ubuntu-18.04, r: 'oldrel-2'}
- {os: ubuntu-18.04, r: 'oldrel-3'}
- {os: ubuntu-18.04, r: 'oldrel-4'}
- {os: ubuntu-20.04, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-20.04, r: 'release'}
- {os: ubuntu-20.04, r: 'oldrel-1'}
- {os: ubuntu-20.04, r: 'oldrel-2'}
- {os: ubuntu-20.04, r: 'oldrel-3'}
- {os: ubuntu-20.04, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
linters: with_defaults(
linters: linters_with_defaults(
line_length_linter(120),
T_and_F_symbol_linter,
absolute_path_linter,
nonportable_path_linter,
semicolon_terminator_linter,
semicolon_linter,
undesirable_operator_linter
)
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ggcheck
Title: Inspect 'ggplot2' Plots for Automated Grading in Learning Exercises
Version: 0.0.4
Version: 0.0.5
Authors@R: c(
person("Garrick", "Aden-Buie", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-7111-0077")),
Expand All @@ -23,7 +23,7 @@ URL: https://github.com/rstudio/ggcheck
BugReports: https://github.com/rstudio/ggcheck/issues
Imports:
ggplot2,
gradethis (>= 0.2.4.9000),
gradethis (>= 0.2.12.9004),
purrr,
rlang,
utils
Expand All @@ -36,4 +36,4 @@ Config/Needs/website: pkgdown, tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ S3method(get_data,ggplot)
S3method(get_data,layer_to_check)
S3method(get_mappings,ggplot)
S3method(get_mappings,layer_to_check)
S3method(gradethis_equal,ggplot)
export(.result)
export(default_label)
export(default_param)
Expand Down Expand Up @@ -45,3 +46,4 @@ export(uses_stat_param)
export(uses_stats)
importFrom(gradethis,.result)
importFrom(gradethis,fail)
importFrom(gradethis,gradethis_equal)
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit -->
# ggcheck 0.0.5

* Add `gradethis_equal()` method for `ggplot` objects (#37).

# ggcheck 0.0.4 (2022-04-14)

Expand Down
1 change: 0 additions & 1 deletion R/geoms.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' List the geoms used by a plot
#'
#' \code{get_geoms} returns a vector of geom names, written as character
Expand Down
25 changes: 25 additions & 0 deletions R/gradethis_equal.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#' Compare two `ggplot`s to check whether they are equal
#'
#' @param x,y Two `ggplot` objects to compare
#' @param ... Unused
#'
#' @seealso [gradethis::gradethis_equal()] for the generic function.
#' @inherit gradethis::gradethis_equal return
#' @importFrom gradethis gradethis_equal
#' @export
#'
#' @examples
#' library(ggplot2)
#' library(ggcheck)
#' library(gradethis)
#'
#' cty_plot <- ggplot(mpg, aes(x = displ, y = cty)) + geom_point()
#' hwy_plot <- ggplot(mpg, aes(x = displ, y = cty)) + geom_point()
#'
#' gradethis_equal(cty_plot, hwy_plot)
#' gradethis_equal(cty_plot, cty_plot)
gradethis_equal.ggplot <- function(x, y, ...) {
try(ggplot2::ggplot_build(x), silent = TRUE)
try(ggplot2::ggplot_build(y), silent = TRUE)
NextMethod()
}
1 change: 0 additions & 1 deletion R/layers.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' How many layers are in a plot?
#'
#' @param p A ggplot object
Expand Down
1 change: 0 additions & 1 deletion R/stats.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' List the stats used by a plot
#'
#' \code{get_stats} returns a vector of stats names, written as character
Expand Down
1 change: 0 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# ggplot2 default mappings from a `geom_` function suffix to geom and stat class names when
# creating a layer using a `geom_` function.
# NOTE: this could be dynamically generated as well but would require extra dependency of {sf} package
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ p <-
geom_smooth(se = FALSE, method = "lm")

p
#> `geom_smooth()` using formula 'y ~ x'
#> `geom_smooth()` using formula = 'y ~ x'
```

<img src="man/figures/README-expected-plot-1.png" width="100%" />
Expand Down
Binary file modified man/figures/README-expected-plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/ggcheck-package.Rd

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

33 changes: 33 additions & 0 deletions man/gradethis_equal.ggplot.Rd

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

1 change: 1 addition & 0 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ reference:
- get_default_labels
- get_default_params
- default_label
- gradethis_equal.ggplot

0 comments on commit 155f77d

Please sign in to comment.