The eachElem function forms argument sets from objects passed in via
elementArgs and fixedArgs.
The elements of elementsArgs are used to specify the arguments that are
changing, or varying, from task to task, while the elements of
fixedArgs are used to specify the arguments that do not vary
from task to task. The number of tasks that are executed by a call to
eachElem is basically equal to the length of the longest vector
(or list, etc) in elementArgs. If any elements of
elementArgs are shorter, then their values are recycled, using
the standard R rules. The elements of elementArgs may be vectors, lists, matrices, or
data frames. The vectors and lists are always iterated over by
element, or "cell", but matrices and data frames can also be iterated
over by row or column. This is controlled by the by option,
specified via the eo argument. See below for more information.
For example:
eachElem(s, '+', elementArgs=list(1:4), fixedArgs=list(100))
This will submit four tasks, since the length of 1:4 is four. The
four tasks will be to add the arguments 1 and 100, 2 and 100, 3 and
100, and 4 and 100. The result is a list containing the four values
101, 102, 103, and 104.
Another way to do the same thing is with:
eachElem(s, '+', elementArgs=list(1:4, 100))
Since the second element of elementArgs is length one, it's
value is recycled four times, thus specifying the same set of tasks as
in the previous example. This method also has the advantage of making it
easy to put fixed values before varying values, without the need for
the eo$argPermute option, discussed later. For example:
eachElem(s, '-', elementArgs=list(100, 1:4))
is similar to the R statement:
100 - 1:4
Note that in simple examples like these, where the results are numeric
values, the standard R unlist function can be very
useful for converting the resulting list into a vector.