Creates and returns a grid object using the function given by `grobFun` when `test` is `TRUE` Otherwise a simple `grob()` is produced with the same parameters. All grob parameters are given in `...`.

condGrob(test = TRUE, grobFun = grob, name = "grob name", ...)

Arguments

test

Either `TRUE` or `FALSE` to indicate whether `grobFun` is to be used (default `TRUE`) or not.

grobFun

The function to be used to create the grob when `test = TRUE` (e.g. `textGrob`, `polygonGrob`, etc.).

name

The name to be used for the returned grob.

...

The arguments to be given to the `grobFun` (or to `grob()` when `test = FALSE`).

Value

A grob as produced by either the `grobFun` given or by `grob()` using the remaining arguments. If `test = FALSE` then the name is suffixed by ": `grobFun name` arguments".

Examples

myGrob <- condGrob(test = (runif(1) > 0.5), grobFun = textGrob, name = "my label", label = "Some random text")
#> Error in condGrob(test = (runif(1) > 0.5), grobFun = textGrob, name = "my label", label = "Some random text"): object 'textGrob' not found
myGrob
#> Error in eval(expr, envir, enclos): object 'myGrob' not found