is_ggplot()
tests if an object is a ggplot.
stop_if_not_ggplot()
signals an error if an object is not
a ggplot.
fail_if_not_ggplot()
returns a failing grade if an
object is not a ggplot.
Usage
is_ggplot(p)
stop_if_not_ggplot(p, message = getOption("ggcheck.error"))
fail_if_not_ggplot(
p = .result,
message = getOption("ggcheck.fail"),
env = parent.frame()
)
Arguments
- p
An object
- message
A message to be displayed if
p
is not a ggplot object.- env
Environment in which to find
.result
. Most users ofggcheck
will not need to use this argument.
Value
is_ggplot()
returns TRUE
if p
is a ggplot
object; otherwise it returns FALSE
.
stop_if_not_ggplot()
returns an error if p
is not a
ggplot object; other it invisibly returns NULL
.
fail_if_not_ggplot()
returns a failing grade if p
is
not a ggplot object; other it invisibly returns NULL
.
Examples
require(ggplot2)
p_valid <- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
geom_point()
is_ggplot(p_valid)
#> [1] TRUE
stop_if_not_ggplot(p_valid)
fail_if_not_ggplot(p_valid)
p_invalid <- geom_point()
is_ggplot(p_invalid)
#> [1] FALSE
if (FALSE) {
stop_if_not_ggplot(p_invalid)
}
fail_if_not_ggplot(p_valid)