I want to concatenate the below urls, I have written a below function to concatenate all the urls:
library(datetime)
library(lubridate)
get_thredds_url<- function(mon, hr){
a <-"http://abc.co.in/"
b <-"thredds/path/"
c <-paste0("%02d", ymd_h(mon))
d <-paste0(strftime(datetime_group, format="%Y%m%d%H"))
e <-paste0("/gfs.t%sz.pgrb2.0p25.f%03d",(c, hr))
url <-paste0(a,b,b,d)
return (url)
}
mon = datetime(2017, 9, 26, 0)
hr = 240
url = get_thredds_url(mon,hr)
print (url)
But I am getting below error when I execute the definition of get_thredds_url():
Error: unexpected ',' in: " d<-paste0(strftime(datetime_group, format="%Y%m%d%H")) e<-paste0("/gfs.t%sz.pgrb2.0p25.f%03d",(c," url <-paste0(a,b,b,d)
Error in paste0(a, b, b, d) : object 'a' not found return (url) Error: no function to return from, jumping to top level } Error: unexpected '}' in "}"
What is wrong with my function and how can I solve this?
The final output should be:
http://abc.co.in/thredds/path/2017092600/gfs.t00z.pgrb2.0p25.f240
candurlare pre-defined functions inR, consider using better variable names. second, you have not defineddatetimeorymd_h, are these loaded from a package? finally, in your line in the function where you defineetry:e<-paste0("/gfs.t%sz.pgrb2.0p25.f%03d", c(cc, hr)). note thatccis what you callcin your functiondatetime_groupisn't defined either. please edit your question to be bettere<-paste0("/gfs.t%sz.pgrb2.0p25.f%03d",(c, hr)). You can't use (c,hr) like that - usee<-paste0("/gfs.t%sz.pgrb2.0p25.f%03d",c, hr). Let us know what happens once you change this. The other comments above are important too - make sure you read up on providing reproducible examples when posting on StackOverflow.