Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Bert Gunter
... and note also: > f <- function(...)list(...) <- list(...) ## you cannot have list(...) on LHS > f(x=1,y="a") Error in list(...) <- list(...) : '...' used in an incorrect context In addition to Eric's suggestions, maybe something like this construction is useful: Lapply_me = function(X = X

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Christofer Bogaso
Thanks Eric, this is working. On Sun, Mar 4, 2018 at 11:28 PM, Eric Berger wrote: > 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 bei

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Eric Berger
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 t

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Christofer Bogaso
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'] } r

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Eric Berger
That's fine. The issue is how you called Lapply_me(). What did you pass as the argument 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.christo...@gmail.com> wrote: > My modifie

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Christofer Bogaso
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 a

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Eric Berger
Hi Christofer, Before you made the change that I suggested, your program was stopping at the statement: list(...) = list(..) .etc This means that it never tried to execute the statement: return(lapply(X,FUN,...)) Now that you have made the change, it gets past the first statement and tries to execu

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Christofer Bogaso
@Eric - with this approach I am getting below error : Error in FUN(X[[i]], ...) : unused argument (list()) On Sun, Mar 4, 2018 at 10:18 PM, Eric Berger wrote: > Hi Christofer, > You cannot assign to list(...). You can do the following > > myList <- list(...)[!names(list(...)) %in% 'mc.cores'] >

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Eric Berger
Hi Christofer, You cannot assign to list(...). You can do the following myList <- list(...)[!names(list(...)) %in% 'mc.cores'] HTH, Eric On Sun, Mar 4, 2018 at 6:38 PM, Christofer Bogaso < bogaso.christo...@gmail.com> wrote: > Hi, > > As an example, I want to create below kind of custom Functio

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Christofer Bogaso
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(

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Duncan Murdoch
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 do

[R] Change Function based on ifelse() condtion

2018-03-04 Thread Christofer Bogaso
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 f