One of R
's greatest feature is lazy evaluation. This leads to the often encountered style that one can use an arguments as the value of another arguments. For example, in Hadley's great book on Advanced R you see this example:
g <- function(a = 1, b = a * 2) {
c(a, b)
}
g()
#> [1] 1 2
g(10)
#> [1] 10 20
Now, I would like to do the same for plot with xlim
and ylim
, however, it is not working:
> plot(1, 1, ylim = c(0,1), xlim = ylim)
Error in plot.default(1, 1, ylim = c(0, 1), xlim = ylim) :
object 'ylim' not found
> plot(1, 1, xlim = c(0,1), ylim = xlim)
Error in plot.default(1, 1, xlim = c(0, 1), ylim = xlim) :
object 'xlim' not found
- Does anybody know why?
- Is there a way to still achieve this?