Displaying 10 results from an estimated 10 matches for "apply_mc".
2018 Mar 04
3
Change Function based on ifelse() condtion
Below is my full implementation (tried to make it simple as for demonstration)
Lapply_me = function(X = X, FUN = FUN, Apply_MC = FALSE, ...) {
if (Apply_MC) {
return(mclapply(X, FUN, ...))
} else {
if (any(names(list(...)) == 'mc.cores')) {
myList = list(...)[!names(list(...)) %in% 'mc.cores']
}
return(lapply(X, FUN, myList))
}
}
Lapply_me(as.list(1:4), function(xx) {
if (xx == 1) return('a')
if (...
2018 Mar 04
0
Change Function based on ifelse() condtion
The reason that it works for Apply_MC=TRUE is that in that case you call
mclapply(X,FUN,...) and
the mclapply() function strips off the mc.cores argument from the "..."
list before calling FUN, so FUN is being called with zero arguments,
exactly as it is declared.
A quick workaround is to change the line
Lapply_me(as.list(1...
2018 Mar 04
2
Change Function based on ifelse() condtion
My modified function looks below :
Lapply_me = function(X = X, FUN = FUN, Apply_MC = FALSE, ...) {
if (Apply_MC) {
return(mclapply(X, FUN, ...))
} else {
if (any(names(list(...)) == 'mc.cores')) {
myList = list(...)[!names(list(...)) %in% 'mc.cores']
}
return(lapply(X, FUN, myList))
}
}
Here, I am not passing ... anymore rather passing myList
On Sun, Mar 4, 2018...
2018 Mar 04
0
Change Function based on ifelse() condtion
...nt to FUN?
And if you did not pass anything that how is FUN declared?
You have not shown that in your email.
On Sun, Mar 4, 2018 at 7:11 PM, Christofer Bogaso <
bogaso.christofer at gmail.com> wrote:
> My modified function looks below :
>
> Lapply_me = function(X = X, FUN = FUN, Apply_MC = FALSE, ...) {
> if (Apply_MC) {
> return(mclapply(X, FUN, ...))
> } else {
> if (any(names(list(...)) == 'mc.cores')) {
> myList = list(...)[!names(list(...)) %in% 'mc.cores']
> }
> return(lapply(X, FUN, myList))
> }
> }
>
> Here, I am not passing...
2018 Mar 04
2
Change Function based on ifelse() condtion
Hi,
As an example, I want to create below kind of custom Function which
either be mclapply pr lapply
Lapply_me = function(X = X, FUN = FUN, ..., Apply_MC = FALSE) {
if (Apply_MC) {
return(mclapply(X, FUN, ...))
} else {
if (any(names(list(...)) == 'mc.cores')) {
list(...) = list(...)[!names(list(...)) %in% 'mc.cores']
}
return(lapply(X, FUN, ...))
}
}
However when Apply_MC = FALSE it generates below error saying :
'...' u...
2018 Mar 04
2
Change Function based on ifelse() condtion
...ar 4, 2018 at 6:38 PM, Christofer Bogaso
> <bogaso.christofer at gmail.com> wrote:
>>
>> Hi,
>>
>> As an example, I want to create below kind of custom Function which
>> either be mclapply pr lapply
>>
>> Lapply_me = function(X = X, FUN = FUN, ..., Apply_MC = FALSE) {
>> if (Apply_MC) {
>> return(mclapply(X, FUN, ...))
>> } else {
>> if (any(names(list(...)) == 'mc.cores')) {
>> list(...) = list(...)[!names(list(...)) %in% 'mc.cores']
>> }
>> return(lapply(X, FUN, ...))
>> }
>> }
&g...
2018 Mar 04
0
Change Function based on ifelse() condtion
...> > <bogaso.christofer at gmail.com> wrote:
> >>
> >> Hi,
> >>
> >> As an example, I want to create below kind of custom Function which
> >> either be mclapply pr lapply
> >>
> >> Lapply_me = function(X = X, FUN = FUN, ..., Apply_MC = FALSE) {
> >> if (Apply_MC) {
> >> return(mclapply(X, FUN, ...))
> >> } else {
> >> if (any(names(list(...)) == 'mc.cores')) {
> >> list(...) = list(...)[!names(list(...)) %in% 'mc.cores']
> >> }
> >> return(lapply(X,...
2018 Mar 04
0
Change Function based on ifelse() condtion
...mc.cores']
HTH,
Eric
On Sun, Mar 4, 2018 at 6:38 PM, Christofer Bogaso <
bogaso.christofer at gmail.com> wrote:
> Hi,
>
> As an example, I want to create below kind of custom Function which
> either be mclapply pr lapply
>
> Lapply_me = function(X = X, FUN = FUN, ..., Apply_MC = FALSE) {
> if (Apply_MC) {
> return(mclapply(X, FUN, ...))
> } else {
> if (any(names(list(...)) == 'mc.cores')) {
> list(...) = list(...)[!names(list(...)) %in% 'mc.cores']
> }
> return(lapply(X, FUN, ...))
> }
> }
>
> However when Apply_MC = FALS...
2018 Mar 04
2
Change Function based on ifelse() condtion
Hi again,
I am looking for some way to alternately use 2 related functions,
based on some ifelse() condition.
For example, I have 2 functions mclapply() and lapply()
However, mclapply() function has one extra parameter 'mc.cores' which
lapply doesnt not have.
I know when mc.cores = 1, these 2 functions are essentially same,
however I am looking for more general way to control them
2018 Mar 04
0
Change Function based on ifelse() condtion
On 04/03/2018 10:39 AM, Christofer Bogaso wrote:
> Hi again,
>
> I am looking for some way to alternately use 2 related functions,
> based on some ifelse() condition.
>
> For example, I have 2 functions mclapply() and lapply()
>
> However, mclapply() function has one extra parameter 'mc.cores' which
> lapply doesnt not have.
>
> I know when mc.cores =