.
Best regards,
Florian
Gesendet: Mittwoch, 14. März 2018 um 19:05 Uhr
Von: "Henrik Bengtsson" <henrik.bengts...@gmail.com>
An: "Florian Schwendinger" <florian_schwendin...@gmx.at>
Cc: fschw...@wu.ac.at, R-devel <r-devel@r-project.org>
Betreff: Re: [Rd] clusterApply arguments
This is nothing specific to parallel::clusterApply() per se. It is the
default behavior of R where it allows for partial argument names. I
don't think there's much that can be done here except always using
fully named arguments to the "apply" function itself as you show.
You can "alert" yourself when there's a mistake by using:
options(warnPartialMatchArgs = TRUE)
e.g.
clusterApply(clu, x = 1:2, fun = fun, c = 1) ## Error
Warning in clusterApply(clu, x = 1:2, fun = fun, c = 1) :
partial argument match of 'c' to 'cl'
Error in checkCluster(cl) : not a valid cluster
It's still only a warning, but an informative one.
/Henrik
On Wed, Mar 14, 2018 at 8:50 AM, Florian Schwendinger
<florian_schwendin...@gmx.at> wrote:
Hi!
I recognized that the argument matching of clusterApply (and
therefore parLapply) goes wrong when one of the arguments of the
function is called "c". In this case, the argument "c" is used as
cluster and the functions give the following error message "Error
in checkCluster(cl) : not a valid cluster".
Of course, "c" is for many reasons an unfortunate argument name and
this can be easily fixed by the user side.
See below for a small example.
library(parallel)
clu <- makeCluster(2, "PSOCK")
fun <- function(x0, x1) (x0 + x1)
clusterApply(clu, x = 1:2, fun = fun, x1 = 1) ## OK
parLapply(cl = clu, X = 1:2, fun = fun, x1 = 1) #OK
fun <- function(b, c) (b + c)
clusterApply(clu, x = 1:2, fun = fun, c = 1) ## Error
clusterApply(cl = clu, x = 1:2, fun = fun, c = 1) ## OK
parLapply(cl = clu, X = 1:2, fun = fun, c = 1) ## Error
stopCluster(clu)
I used "R version 3.4.3 Patched (2018-01-07 r74099".
Best regards,
Florian
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel[https://stat.ethz.ch/mailman/listinfo/r-devel]