tests/testthat/test-parallel.r

context("Parallel")

with_parallel <- function(code) {
  skip_on_cran()
  skip_if_not_installed("doParallel")

  doParallel::registerDoParallel(cores = 2)
  on.exit(doParallel::stopImplicitCluster())
  code
}

# test_that("l_ply respects .parallel", {
#   with_parallel(
#     expect_that(
#       l_ply(c(0.1, 0.1), Sys.sleep, .parallel = TRUE),
#       takes_less_than(0.18))
#   )
# })

test_that("l_ply + .parallel complains about invalid arguments", {
  with_parallel({
    expect_message(
      l_ply(1:10, force, .parallel = TRUE, .print = TRUE),
      "Printing disabled")
    expect_message(
      l_ply(1:10, force, .parallel = TRUE, .progress = "text"),
      "Progress disabled")
  })
})

test_that("llply + .parallel complains about invalid arguments", {
  with_parallel({
    expect_message(
      llply(1:10, force, .parallel = TRUE, .progress = "text"),
      "Progress disabled")
  })
})

test_that(".paropts passes options to foreach", {
  combine <- function(a, b) NULL
  with_parallel(x <- llply(1:10, identity, .parallel = TRUE,
    .paropts = list(.combine = combine)))
  expect_equal(x, NULL)
})

Try the plyr package in your browser

Any scripts or data that you put into this service are public.

plyr documentation built on Oct. 2, 2023, 9:07 a.m.