Skip to content

using foreach function with gtrendsR

1 message · samarvir singh

#
I have this code which is working

library("checkpoint")
library("gtrendsR")
library("doParallel")

cl<-makeCluster(4)
registerDoParallel(cl)
gconnect(usr = "email at gmail.com", psw = "password", verbose = FALSE)

names <- c("apple","shit", "android", "rocks")
formula <- function(x){
x0 <- gtrends(x, res = "7d")
x1 <- x0[3]
x2 <- as.data.frame(x1)
x3 <- x2[1,2]return(x3)}
for( x in names)
{

   x5 <- rbind(x5,formula(x))
}

Now, I want to process this code with parallel processing, so I am using
foreach function

How can I do the same for foreach loop?