Skip to content

Commit 155f77d

Browse files
authored
Add gradethis_equal() method for ggplot objects (#37)
Co-authored-by: rossellhayes <rossellhayes@users.noreply.github.com>
1 parent b784777 commit 155f77d

File tree

15 files changed

+77
-18
lines changed

15 files changed

+77
-18
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ jobs:
2929
- {os: windows-latest, r: '3.6'}
3030

3131
# Use older ubuntu to maximise backward compatibility
32-
- {os: ubuntu-18.04, r: 'devel', http-user-agent: 'release'}
33-
- {os: ubuntu-18.04, r: 'release'}
34-
- {os: ubuntu-18.04, r: 'oldrel-1'}
35-
- {os: ubuntu-18.04, r: 'oldrel-2'}
36-
- {os: ubuntu-18.04, r: 'oldrel-3'}
37-
- {os: ubuntu-18.04, r: 'oldrel-4'}
32+
- {os: ubuntu-20.04, r: 'devel', http-user-agent: 'release'}
33+
- {os: ubuntu-20.04, r: 'release'}
34+
- {os: ubuntu-20.04, r: 'oldrel-1'}
35+
- {os: ubuntu-20.04, r: 'oldrel-2'}
36+
- {os: ubuntu-20.04, r: 'oldrel-3'}
37+
- {os: ubuntu-20.04, r: 'oldrel-4'}
3838

3939
env:
4040
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

.lintr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
linters: with_defaults(
1+
linters: linters_with_defaults(
22
line_length_linter(120),
33
T_and_F_symbol_linter,
44
absolute_path_linter,
55
nonportable_path_linter,
6-
semicolon_terminator_linter,
6+
semicolon_linter,
77
undesirable_operator_linter
88
)

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ggcheck
22
Title: Inspect 'ggplot2' Plots for Automated Grading in Learning Exercises
3-
Version: 0.0.4
3+
Version: 0.0.5
44
Authors@R: c(
55
person("Garrick", "Aden-Buie", , "garrick@rstudio.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-7111-0077")),
@@ -23,7 +23,7 @@ URL: https://github.com/rstudio/ggcheck
2323
BugReports: https://github.com/rstudio/ggcheck/issues
2424
Imports:
2525
ggplot2,
26-
gradethis (>= 0.2.4.9000),
26+
gradethis (>= 0.2.12.9004),
2727
purrr,
2828
rlang,
2929
utils
@@ -36,4 +36,4 @@ Config/Needs/website: pkgdown, tidyverse/tidytemplate
3636
Config/testthat/edition: 3
3737
Encoding: UTF-8
3838
Roxygen: list(markdown = TRUE)
39-
RoxygenNote: 7.1.2
39+
RoxygenNote: 7.2.3

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ S3method(get_data,ggplot)
44
S3method(get_data,layer_to_check)
55
S3method(get_mappings,ggplot)
66
S3method(get_mappings,layer_to_check)
7+
S3method(gradethis_equal,ggplot)
78
export(.result)
89
export(default_label)
910
export(default_param)
@@ -45,3 +46,4 @@ export(uses_stat_param)
4546
export(uses_stats)
4647
importFrom(gradethis,.result)
4748
importFrom(gradethis,fail)
49+
importFrom(gradethis,gradethis_equal)

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit -->
1+
# ggcheck 0.0.5
2+
3+
* Add `gradethis_equal()` method for `ggplot` objects (#37).
24

35
# ggcheck 0.0.4 (2022-04-14)
46

R/geoms.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#' List the geoms used by a plot
32
#'
43
#' \code{get_geoms} returns a vector of geom names, written as character

R/gradethis_equal.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#' Compare two `ggplot`s to check whether they are equal
2+
#'
3+
#' @param x,y Two `ggplot` objects to compare
4+
#' @param ... Unused
5+
#'
6+
#' @seealso [gradethis::gradethis_equal()] for the generic function.
7+
#' @inherit gradethis::gradethis_equal return
8+
#' @importFrom gradethis gradethis_equal
9+
#' @export
10+
#'
11+
#' @examples
12+
#' library(ggplot2)
13+
#' library(ggcheck)
14+
#' library(gradethis)
15+
#'
16+
#' cty_plot <- ggplot(mpg, aes(x = displ, y = cty)) + geom_point()
17+
#' hwy_plot <- ggplot(mpg, aes(x = displ, y = cty)) + geom_point()
18+
#'
19+
#' gradethis_equal(cty_plot, hwy_plot)
20+
#' gradethis_equal(cty_plot, cty_plot)
21+
gradethis_equal.ggplot <- function(x, y, ...) {
22+
try(ggplot2::ggplot_build(x), silent = TRUE)
23+
try(ggplot2::ggplot_build(y), silent = TRUE)
24+
NextMethod()
25+
}

R/layers.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#' How many layers are in a plot?
32
#'
43
#' @param p A ggplot object

R/stats.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#' List the stats used by a plot
32
#'
43
#' \code{get_stats} returns a vector of stats names, written as character

R/utils.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# ggplot2 default mappings from a `geom_` function suffix to geom and stat class names when
32
# creating a layer using a `geom_` function.
43
# NOTE: this could be dynamically generated as well but would require extra dependency of {sf} package

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ p <-
4848
geom_smooth(se = FALSE, method = "lm")
4949

5050
p
51-
#> `geom_smooth()` using formula 'y ~ x'
51+
#> `geom_smooth()` using formula = 'y ~ x'
5252
```
5353

5454
<img src="man/figures/README-expected-plot-1.png" width="100%" />
-964 Bytes
Loading

man/ggcheck-package.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/gradethis_equal.ggplot.Rd

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgdown/_pkgdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ reference:
7676
- get_default_labels
7777
- get_default_params
7878
- default_label
79+
- gradethis_equal.ggplot

0 commit comments

Comments
 (0)