Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify function parameters in do.call

Tags:

r

Lets say I have a function that fetches data from Yahoo called Yahoo.Fetch, and I run a do.call on the function, which would be:

do.call(merge.xts, lapply(list.of.tickers, Yahoo.Fetch))

The default would have all=TRUE in merge.xts, so how would I be able to specify in a do.call to have all=FALSE? This is just an example, but I would like to know how to change and specify parameters in apply, do.call, lapply functions.

like image 912
TTT Avatar asked Aug 15 '13 21:08

TTT


1 Answers

You can add it as a named value to the existing list with c() which returns another list:

do.call(merge.xts, c( lapply(list.of.tickers, Yahoo.Fetch), all=FALSE ))

Or wrap the parameter in with an anonymous helper function:

do.call( function(x) merge.xts(x, all=FALSE), 
               lapply(list.of.tickers, Yahoo.Fetch))
like image 100
IRTFM Avatar answered Nov 06 '22 21:11

IRTFM