From tomas.kalibera at gmail.com  Fri Mar 16 18:36:28 2018
From: tomas.kalibera at gmail.com (Tomas Kalibera)
Date: Fri, 16 Mar 2018 18:36:28 +0100
Subject: [Rd] clusterApply arguments
In-Reply-To: <0870b4c1-d7ac-29a9-8215-671bac51c26d@gmail.com>
References: <trinity-9abb96df-40b2-4e2d-a112-1f2e8a032353-1521042659731@3c-app-gmx-bs70>
 <CAFDcVCRUoLVcr7ByUE0eABt+n5Tjj_RTZjsO6iVpbih0b8wxuw@mail.gmail.com>
 <trinity-a8e04674-7da0-43cc-86cf-9e9d4189ecb4-1521110354065@3c-app-gmx-bs25>
 <CAFDcVCTdERGnFHWsx4hr5DVfsvhVV9o3EzMVKrb9NJ6CKu7=Mg@mail.gmail.com>
 <0870b4c1-d7ac-29a9-8215-671bac51c26d@gmail.com>
Message-ID: <a02e404f-e6fb-d047-156c-43883abc2b8c@gmail.com>

Fixed in R-devel (74418).
Tomas

On 03/15/2018 08:57 PM, Tomas Kalibera wrote:
> On 03/15/2018 05:25 PM, Henrik Bengtsson wrote:
>> On Thu, Mar 15, 2018 at 3:39 AM, <FlorianSchwendinger at gmx.at> wrote:
>>> Thank you for your answer!
>>> I agree with you except for the 3 (Error) example and
>>> I realize now I should have started with that in the explanation.
>>>
>>> ?From my point of view
>>> parLapply(cl = clu, X = 1:2, fun = fun, c = 1)
>>> shouldn't give an error.
>>>
>>> This could be easily avoided by using all the argument
>>> names in the custerApply call of parLapply which means changing,
>>>
>>> parLapply <- function(cl = NULL, X, fun, ...)? {
>>> ???? cl <- defaultCluster(cl)
>>> ???? do.call(c, clusterApply(cl, x = splitList(X, length(cl)),
>>> ???????????? fun = lapply, fun, ...), quote = TRUE)
>>> }
>>>
>>> to
>>>
>>> parLapply <- function (cl = NULL, X, fun, ...)? {
>>> ???? cl <- defaultCluster(cl)
>>> ???? do.call(c, clusterApply(cl = cl, x = splitList(X, length(cl)),
>>> ???????????? fun = lapply, fun, ...), quote = TRUE)
>>> }
>> Oh... sorry I missed that point.? Yes, I agree, this should be a
>> trivial fix to the 'parallel' package.
>>
>> /Henrik
> Yes, thanks for the report, I am testing a fix for this (and other 
> missing argument names in calls involving ...) in parallel.
> Tomas
>>
>>> .
>>>
>>> Best regards,
>>> Florian
>>>
>>>
>>>
>>> Gesendet: Mittwoch, 14. M?rz 2018 um 19:05 Uhr
>>> Von: "Henrik Bengtsson" <henrik.bengtsson at gmail.com>
>>> An: "Florian Schwendinger" <Florian_Schwendinger at gmx.at>
>>> Cc: fschwend at wu.ac.at, R-devel <r-devel at 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_Schwendinger at 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 at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel[https://stat.ethz.ch/mailman/listinfo/r-devel] 
>>>
>>>
>>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



[Rd] clusterApply arguments
Tomas Kalibera