6

I'm doing some analysis something like this:

library(plyr)
input.files <- c("file1.txt", "file2.txt", "file3.txt")
input.data <- llply(input.files, load.file, .parallel=TRUE)
step.one.results <- llply(input.data, step.one, .parallel=TRUE)
step.two.results <- llply(step.one.results, step.two, .parallel=TRUE)
...
step.N.results <- llply(`step.N-1.results`, step.N, .parallel=TRUE)
...

Is there any way to make all the plyr functions parallel by default, so I don't always have to specify .parallel=TRUE for each step?

Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
  • In addition to the solution below, it looks like there's a function called `set.defaults` in the `diversitree` package that can do this. – Jake Fisher Feb 10 '16 at 18:29

2 Answers2

10
library(Defaults)
setDefaults(llply, .parallel=TRUE)

You'd have to setDefaults on every function for which you want to change the default formals. You can put this in your .Rprofile if you like.

You can also mess with the formals directly. e.g. formals(llply)$.parallel <- TRUE should work.

GSee
  • 48,880
  • 13
  • 125
  • 145
  • 1
    Just FYI, it looks like the Defaults package is no longer available on CRAN, so you'll have to mess with the formals directly. – Jake Fisher Feb 10 '16 at 18:27
1

From my answer to another question:

As the Defaults package is no longer available from CRAN, you can use default.

As an example:

x <- list(a = 1, b = 2, c = 3)
default::default(unlist) <- list(use.names = FALSE)
unlist(x)
#> [1] 1 2 3

unlist <- default::reset_default(unlist)
unlist(x)
#> a b c 
#> 1 2 3

Created on 2019-03-22 by the reprex package (v0.2.0.9000).

  • Thanks for your input! Unfortunately [stack overflow's policy](https://meta.stackoverflow.com/questions/251006/flagging-link-only-answers) is that answers should provide a solution even if the link gets removed. Please edit your question accordingly, or use a comment instead. Thanks! – Nino Filiu Mar 22 '19 at 15:35
  • Thank you! According to your request, I have lazily copied my answer from the related question. Is it correct ? – Alain Danet Mar 22 '19 at 16:28
  • Yup! As long as your answer makes sense even without the link, it's all good. – Nino Filiu Mar 22 '19 at 17:44