hadley/devtools — pull request #121 by wch (2012-07-26 18:42:04+00:00)
Title: Add 'threads' option to check_cran

This adds parallel checking to `check_cran`, by using `mclapply`.

There are a couple weird things happening: if the number of packages to check is less than or equal the number of threads, it gives errors. I think it only happens when `mc.preschedule` is FALSE. I think this involves some interaction between `mclapply` and the external system calls, but I'm not completely sure.

```
# 1 packages, 1 thread
# Error
check_cran('bisectr', threads=1, libpath='~/R-temp')
# Checking 1 CRAN packages
# Determining available packages
# Checking 1: bisectr
#
# Error in sum(sapply(res, inherits, "try-error")) :
# invalid 'type' (list) of argument

# 2 packages, 1 thread
# OK
check_cran(c('bisectr', 'stringr'), threads=1, libpath='~/R-temp')
# Checking 2 CRAN packages
# Determining available packages
# Checking 1: bisectr
#
# Downloading stringr
# Checking 2: stringr
# Running 'test-all.R'

# 2 packages, 2 threads
# Error
check_cran(c('bisectr', 'stringr'), threads=2, libpath='~/R-temp')
# Checking 2 CRAN packages
# Determining available packages
# Checking 1: bisectr
# Checking 2: stringr
# Running 'test-all.R'
#
# Error in sum(sapply(res, inherits, "try-error")) :
# invalid 'type' (list) of argument

# 3 packages, 2 threads
# OK
check_cran(c('bisectr', 'stringr', 'scales'), threads=2, libpath='~/R-temp')
# Checking 3 CRAN packages
# Determining available packages
# Checking 1: bisectr
# Checking 2: stringr
# Running 'test-all.R'
#
# Checking 3: scales
#
# Running 'test-all.R'
```

I tried but wasn't able to replicate it when I created my own functions and gave them to `mclapply`. Here's the sample code:

```
dat <- list(a = "First", b = "second", c = "third")

extfun <- function(x) {
system2("echo", x)
NULL
}

# OK
lapply(dat, extfun)

# OK
mclapply(dat, extfun, mc.preschedule=FALSE, mc.cores = 1)

```