title: R Parallel Programming: Error in { : task 1 failed - "could not find function "%>%""
body: <p>I tried to do Parallel Programming in R by modified my script. On my script I did two parallel programming. First one was done but the second was error whereas the script structure were same. Below is my code:</p>
  
  <pre><code>library(rvest)
  library(RMySQL)
  library(curl)
  library(gdata)
  library(doMC)
  library(foreach)
  library(doParallel)
  library(raster)
  
  
  trim &lt;- function (x) gsub("^\\s+|\\s+$", "", x)
  
  setwd('/home/chandra/R/IlmuOne/MisterAladin')
  
  no_cores &lt;- detectCores() 
  cl&lt;-makeCluster(no_cores)
  registerDoParallel(cl)
  
  MasterData = read.xls("Master Hotels - FINAL.xlsx", sheet = 1, header = TRUE)
  MasterData$url_agoda = as.character(MasterData$url_agoda)
  
  today = as.Date(format(Sys.time(), "%Y-%m-%d"))+2
  
  ntasks &lt;- nrow(MasterData)
  
  #This section perfomed well
  foreach(i=1:ntasks) %dopar% {    
    url = MasterData$url_agoda[i]        
    if (trim(url)!='-' &amp; trim(url)!='')
    {
      from = gregexpr(pattern ='=',url)[[1]][1]
      piece1 = substr(url,1,from)
      from = gregexpr(pattern ='&amp;los=',url)[[1]][1]
      piece2 = substr(url,from,nchar(url))
      MasterData$url_agoda[i] = paste0(piece1,today,piece2)  
    }   
  }
  
  con &lt;-  dbConnect(RMySQL::MySQL(), username = "root", password = "master",host = "localhost", dbname = "mister_aladin")
  
  
  
  #Tried first 10 data
  #Below section was error and always return error: Error in { : task 1 failed - "could not find function "%&gt;%""
  foreach(a=1:10, .packages='foreach') %dopar% {
  
  
    hotel_id = MasterData$id[a]
    vendor = 'Agoda'
    url = MasterData$url_agoda[a]    
  
    if (url!='-')
    {
  
      tryCatch({                  
        hotel &lt;- curl(url) %&gt;%
          read_html() %&gt;%        
          html_nodes(xpath='//*[@id="room-grouping"]') %&gt;%
          html_table(fill = TRUE)
        hotel &lt;- hotel[[1]]
  
        hotel$hotel_id= hotel_id
        hotel$vendor= vendor
  
        colnames(hotel)[1] = 'TheSpace'
        colnames(hotel)[4] = 'PricePerNight'
  
        room = '-'
        hotel$NormalPrice = 0
        hotel$FinalPrice = 0
  
        for(i in 1:nrow(hotel))
        {
  
          if (i==1 | (!grepl('See photos',hotel$TheSpace[i]) &amp; hotel$TheSpace[i]!='') )  
          {
            room = hotel$TheSpace[i]
          }
          hotel$TheSpace[i] = room
  
          #Normal Price
          if (gregexpr(pattern ='IDR',hotel$PricePerNight[i])[[1]][1][1]==1)
          {
            split = strsplit(hotel$PricePerNight[i],'\n')[[1]]
            NormalPrice = trim(split[2])
            hotel$NormalPrice[i] = NormalPrice            
            NormalPrice = as.integer(gsub(",","",NormalPrice))
            hotel$NormalPrice[i] = NormalPrice          
          }        
  
          #Final Price
          if (gregexpr(pattern ='IDR',hotel$PricePerNight[i])[[1]][1][1]==1)
          {
            split = strsplit(hotel$PricePerNight[i],'\n')[[1]]
            FinalPrice = trim(split[6])
            hotel$FinalPrice[i] = FinalPrice
            FinalPrice = as.integer(gsub(",","",FinalPrice))
            hotel$FinalPrice[i] = FinalPrice
          }
  
          hotel$NormalPrice[is.na(hotel$NormalPrice)] &lt;- 0
          hotel$FinalPrice[is.na(hotel$FinalPrice)] &lt;- 0
  
        }
  
        hotel = hotel[which(hotel$FinalPrice!=0),c("TheSpace","NormalPrice","FinalPrice")]
        colnames(hotel) = c('room','normal_price','final_price')
  
        hotel$log = format(Sys.time(), "%Y-%m-%d %H:%M:%S")
        hotel$hotel_id = hotel_id
        hotel$vendor = vendor
  
  
        Push = hotel[,c('hotel_id','room','normal_price','final_price','vendor','log')]
  
        #print(paste0('Agoda: push one record, hotel id ',hotel_id,'!'))
        #cat(paste(paste0('Agoda: push one record, hotel id ',hotel_id,'!'),'\n'))      
        dbWriteTable(conn=con,name='prices_',value=as.data.frame(Push), append = TRUE, row.names = F)
  
  
      },
      error = function(e) {
        Sys.sleep(2)
        e
      })
  
    }
  
  }
  
  dbDisconnect(con)
  stopImplicitCluster()
  </code></pre>
  
  <p>Every time I run the script it always gives me error: Error in { : task 1 failed - "could not find function "%>%""</p>
  
  <p>I already check every post on this forum and tried to apply it but no one works. </p>
  
  <p>Please advise any solution</p>