This section will talk about how we can batch jobs inside R scripts.
assign()
is similar to "<-",
parse()
can parse a string/text into an expression object which
can be executed by eval()
. At the above, "a", "b", and "d" are
all the same as a vector contains 2 elements "3, 4".
- call and eval
```
a <- function(x, y = 4, detail = FALSE){
ifelse(detail, x+y, 0)
}
b <- list(quote(a), quote(2), quote(3), quote(detail = TRUE))
mode(b) <- "call"
b
(d <- eval(b))
b[[4]] <- FALSE
b
(e <- eval(b))
```
The object "b" is a "call" structure that can be used in eval().
The result for the object "d" should be 5, not 6,
and the object "e" should be 0, as the following.
```
> b
a(2, 3, TRUE)
> (d <- eval(b))
[1] 5
> b[[4]] <- FALSE
> b
a(2, 3, FALSE)
> (e <- eval(b))
[1] 0
```
---