I need to call the same function 10 times, each time with a different year for the end date argument. For example, the end date needs to start as "2011-01-01", then "2012-01-01", then "2013-01-01", etc. How do I loop this function but change the one argument until the last end date is "2020-01-01"?
VI <- mt_subset(product = "MOD13Q1",
band = "250m_16_days_NDVI",
lon = 28.5826,
lat = 1.4368,
start = "2010-01-01",
end = "2011-01-01",
km_lr = 20,
km_ab = 20,
site_name = "Ituri test",
internal = TRUE,
progress = TRUE)
do.call
. This is what it lives for. I would warn though, hitting the MODIS server up in sequential calls is a sure way to get timed out. I would highly recommend capturing errors, eg., failed download. In this way you can figure out where it failed in downloading data without slogging through the in disk results. You can do this withtryCatch
in your looping or call structure. In a for loop you could see a failed download and then move to the next one, which works.for
orlapply
loop isn't it?do.call
withlapply
and really abbrevte the code. I guess that does negate the advice of usingtryCatch
do.call(what, args)
iswhat(args[1], args[2], args[3],...etc...)
. How is that going to callmt_subset
several times? Or are you thinking ofdo.call(stack, lapply(dates, function(date){mt_subset(..date..)}))
?