0

I'm working on a new function for the OEC package (https://cran.r-project.org/web/packages/oec/index.html) so I can batch download data.

Here's my new function that I want to include in my package https://gist.github.com/pachamaltese/3b585dded0a80c031c65e98b268ebcc7

So, this is a MWE

#install.packages("devtools")
library(devtools)
install_github("pachamaltese/oec/cran")

library(oec)

getdata_interval("chl","chn",2010,2014,6,2)

Now I cannot find a general way to rbind the result of that function. If I have 3 years I can do rbind(year_2010, year_2012, year_2014 but as this is supposed to help people and not to annoy then with a long rbind I wonder is there's a way to put rbind("all the dataframes starting with year_") inside the function getdata_interval.

Is there a quite general approach to do that? thanks in advance.

pachamaltese
  • 2,702
  • 4
  • 24
  • 48
  • 3
    The general pattern is `do.call("rbind",list_of_data_frames)`. There are faster alternatives in **dplyr** and **data.table**. This, of course, would strongly argue against your decision to have your function `assign` data frames to the global environment, rather than simply returning a list, which would be more typical and advisable. – joran Jan 25 '17 at 21:39
  • thanks I was trying to use `envir – pachamaltese Jan 25 '17 at 21:45
  • 2
    The last resort is to use `mget()` to create the list of data frames after the fact, but that really shouldn't be necessary if you create the list up front. – joran Jan 25 '17 at 21:47
  • 1
    Regarding Joran's post, take a look at gregor's answer to [this post](http://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames) for tips and tricks with lists of data.frames. – lmo Jan 25 '17 at 21:51
  • @joran I made some changes in the direction you point... inside a function is not quite easy :( I changed my function but now I have another problem that I tried to find my my own ideas + stackoverflow – pachamaltese Jan 26 '17 at 13:36

0 Answers0