In R, arguments have tags, as opposed to just lists. You need to be able to substitute into the tags of a call.
Let's say that we wanted to have a statement "foreach" that worked like "for" but accumulated and returned the results in a list. So an example usage would look like:
sum <- 0 parts <- foreach(i, 1:3, { sum <- sum + i sqrt(i) })
Following the principle of least surprise, let's say we want foreach
to work similarly to for
and mimic R's quirks regarding for
:
That each iteration of the body is and the placeholder variable i
is
defined in the environment enclosing the for
statement.
vec <- i out <- vector(length(i), list) for (iter in seq(len(values))) { i <- vec[[iter]] out[[iter]] <- { sim(a) } }
So far so good. What happens when we want to nest two foreach loops?
out <- function(x) x <- function(i)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.