Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205399

What's the correct way to implement a user-defined do.call's what function?

$
0
0

I have a do.call use-case (as result of calling mclapply) simplified to the following:

myfunc <- function(x, y) {
  str(x)
  #return(x + y)
} 

res <- list(list(x=1,y=1),list(x=2,y=2),list(x=3,y=3))
str(res)

do.call(what="myfunc", res)

No matter what I do in myfunc it never works. I'd expect do.call to call myfunc three times and pass the resp. x and y but instead it calls it once with all the data and complains it doesn't know what to do with the remaining arguments ... what's the correct way to implement the what function such that will apply something over each list element as it does with any other base function?

UPDATE What lead to my confusion over the use of do.call is that I always saw its use to "reduce" the results of a collection. What I didn't realize is that the functions being called by do.call do handle list types and reduce scenarios e.g. rbind


Viewing all articles
Browse latest Browse all 205399

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>