parseJob: Parses a collection of elements into (almost) equal-sized...

Description Usage Arguments Value Author(s) Examples

View source: R/parseJob.R

Description

Parses a collection of elements into (almost) equal-sized groups. Useful for splitting up an R job that operates over a large dataframe or list into multiple jobs.

Usage

1
2
parseJob(n, njobs, collate = FALSE, random.seed = NULL,
  text.to.eval = FALSE)

Arguments

n

The number elements to be parsed

njobs

The number of groups

collate

= TRUE alternative ordering of the grouping. See example below.

random.seed

An integer setting the random seed, which will result in randomizing the elements among the jobs. If NULL, no randomization is performed. Randomization cannot be performed if collate = TRUE or if text.to.eval = TRUE. Randomization is useful when the computing time for each element varies significantly because it helps to even out the run times of parallel jobs.

text.to.eval

If = TRUE, a text expression is returned, that when evaluated, will produce the sequence of elements for that group. This is especially useful when n is very large. (See Value section below).

Value

When text.to.eval = FALSE, a list with njobs elements is returned, each element containing a numeric vector of the element numbers which correspond to that group. When text.to.eval = TRUE, a list with njobs elements is returned, each element containing text (let's call it val), that when evaluated using eval(parse(text = val)), will produce the sequence of numbers corresponding to the group.

Author(s)

Landon Sego

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
x <- parseJob(29, 6)
print(x)

# To see the range of each group
lapply(x, range)

# To see the length of each group
lengths(x)

# Randomize the outcome
parseJob(32, 5, random.seed = 231)

# Example of 'text.to.eval = TRUE'
out <- parseJob(11, 3, text.to.eval = TRUE)
out
lapply(out, function(x) eval(parse(text = x)))

# Example of 'collate = TRUE' and 'text.to.eval = TRUE'
parseJob(11, 3, collate = TRUE)
parseJob(11, 3, collate = TRUE, text.to.eval = TRUE)

Smisc documentation built on May 2, 2019, 2:46 a.m.