title: get online data every hour in R
body: <p>I would like to get the Observatory data every hour they update the forecast.</p>
  
  <p>My one time data extract code is following.</p>
  
  <pre><code>library(RCurl)
  web &lt;- getURL("http://www.hko.gov.hk/contente.htm")
  web &lt;- unlist(strsplit(web, "\r\n"))
  head(web)
  
  temp &lt;- unlist(strsplit(web[1245], "&lt;/span&gt;"))
  MINtemp &lt;- vector()
  MAXtemp &lt;- vector()
  for (i in 1:9){
      mintemp &lt;- substr(temp[2*i-1], 
                nchar(temp[2*i-1])-1, 
                nchar(temp[2*i-1]))
      mintemp &lt;- as.numeric(mintemp)
      MINtemp &lt;- append(MINtemp, mintemp)
  
      maxtemp &lt;- substr(temp[2*i], 
                nchar(temp[2*i])-1, 
                nchar(temp[2*i]))
      maxtemp &lt;- as.numeric(maxtemp)
      MAXtemp &lt;- append(MAXtemp, maxtemp)
  }
  
  status &lt;- strsplit(
               substring(web[1242],12),
          "&lt;/a&gt;&lt;/td&gt;&lt;td align")
  status &lt;- substring(unlist(status), 178)
  weather &lt;- vector()
  for (i in 1:9){
      status[i] &lt;- unlist(strsplit(status[i], "width"))[1]
      weather &lt;- append(weather, 
                  substr(status[i], 
                       1,
                       nchar(status[i])-3
                       )
                  )
  }
  
  RH &lt;- unlist(strsplit(web[1248], "&lt;/span&gt;"))
  MINRH &lt;- vector()
  MAXRH &lt;- vector()
  for (i in 1:9){
      minRH &lt;- substr(RH[2*i-1], 
                nchar(RH[2*i-1])-1, 
                nchar(RH[2*i-1]))
      minRH &lt;- as.numeric(minRH)
      MINRH &lt;- append(MINRH, minRH)
  
      maxRH &lt;- substr(RH[2*i], 
                nchar(RH[2*i])-1, 
                nchar(RH[2*i]))
      maxRH &lt;- as.numeric(maxRH)
      MAXRH &lt;- append(MAXRH, maxRH)
  }
  
  forecast &lt;- paste("+", 1:9, "day(s)", sep=" ")
  current &lt;- as.character(rep(Sys.time(),9))
  DATA &lt;- data.frame(cbind(current,forecast,MINtemp, MAXtemp, MINRH, MAXRH, weather))
  DATA
  </code></pre>
  
  <p>The data i get is </p>
  
  <pre><code>&gt; DATA
  
                    current   forecast MINtemp MAXtemp MINRH MAXRH                                                                          weather
      1 2014-05-04 08:37:55 + 1 day(s)      21      25    80    95 Cloudy with a few showers and thunderstorms. Showers will be more frequent later
      2 2014-05-04 08:37:55 + 2 day(s)      22      25    75    90                        Cloudy with showers. A few squally thunderstorms at first
      3 2014-05-04 08:37:55 + 3 day(s)      21      24    75    95                                                        Cloudy with a few showers
      4 2014-05-04 08:37:55 + 4 day(s)      22      25    80    95                                                        Cloudy with a few showers
      5 2014-05-04 08:37:55 + 5 day(s)      23      26    80    95                              Cloudy with showers and a few squally thunderstorms
      6 2014-05-04 08:37:55 + 6 day(s)      23      26    80    95   Cloudy with showers. Showers will be heavy at times with squally thunderstorms
      7 2014-05-04 08:37:55 + 7 day(s)      22      25    80    95                                    Cloudy with showers and squally thunderstorms
      8 2014-05-04 08:37:55 + 8 day(s)      22      25    70    95                                                 Mainly cloudy with a few showers
      9 2014-05-04 08:37:55 + 9 day(s)      22      26    70    90                                                                    Mainly cloudy
  </code></pre>
  
  <p>I would like the R script run by itself every hour. Then use <code>rbind(DATA, data)</code> to accumulate the dataset. I search similar topic using CMD R BATCH. While can i do that within R like using <code>Sys.sleep()</code> and <code>while(substr(Sys.time(), 15,16)=="00")</code>?</p>
  
  <p>I have searched similar task for scheduling <a href="https://stackoverflow.com/questions/2793389/automating-r-script">This Link</a></p>
  
  <p>That i found Rscript.exe in the directory <code>C:\Program Files\R\R-3.0.2\bin\Rscript.exe</code></p>
  
  <p>and i saved my Rscipt at <code>D:\mydocument\test.r</code> While i still not clear that how to complete the task.</p>