I would like to extract the google trend data through package "gtrendsR" every hour, I tried to use Sys.sleep() function to set the timer, however, it is failure for me to download it every hour. So, how do I correct my code in order to get the data every hour. Thanks a lot!
Sys.setlocale("LC_ALL", "English")
Keywords = c("google", "twitter")
for (k in Keywords) {
res = NULL
temp_1 <- gtrends(k, geo = "US",time = "all")
temp_2 <- temp_1$interest_over_time
res <- rbind(res, temp_2)
rm(temp_1,temp_2)
res <- select (res, c(date, hits))
Sys.setlocale(category = "LC_ALL", locale = "cht")
names(res)[2]<- k
xfilepath = paste("C:/Users/Peter/Desktop/",k,".csv",sep="")
write.csv(res, file = xfilepath, row.names=FALSE)
}