[R] Downloading file with lapply
Santosh Srinivas
santosh.srinivas at gmail.com
Fri Oct 15 09:19:15 CEST 2010
I'm still getting familiar with lapply
I have this date sequence
x <- seq(as.Date("01-Jan-2010",format="%d-%b-%Y"), Sys.Date(), by=1) #to
generate series of dates
I want to apply the function for all values of x . so I use lapply (Still a
newbie!)
I wrote this test function
pFun <- function (x) {
print(paste("This is: ",x,sep=""))
}
When I run it:
> lapply(x,pFun(x))
It gives the result correctly.. but end with an error
Error in match.fun(FUN) :
'pFun(x)' is not a function, character or symbol
Question 1: What is the issue here??
Now, to the real problem. I wrote a function to cmDownFun(sDate)which is
working correctly
If I do cmDownFun (x[6]) .. it works correctly .. (i.e. my function was ok
this time around!)
Hoewever if I do, lapply (x,cmDownFun(x))
It fails at 01-Jan-2010 .... this is because of: HTTP status was '404 Not
Found'
This is OK, because the file does not exist ... but I want to continue for
the remaining values of x
lapply(x,try(cmDownFun(x),silent = TRUE)) .. does not work
I also put the try inside the function itself but does not work either.
----------------------------------------------------------------------------
--------------------------
Thanks R-Helpers. Yes, this is a silly question and it will not be repeated!
:-)
More information about the R-help
mailing list