title: Vectorizing a paste0 for loop in R
body: <p>I'm building a simple scraper in R that handles pagination.  I've tried to use paste0 to loop through the paginated url structure.</p>
  
  <pre><code>#a vector of the urls to scrape
  a &lt;- 1:5
  
  
  URLs &lt;- function(pages) {
  out &lt;- matrix(ncol = 1, nrow = 5)
  for (i in seq_along(a)) {
      fdata &lt;- paste0("https://foo.bar", i, "/")
      out[, i] &lt;- apply(fdata)
  }}
  
  df &lt;- lapply(URLs, function(u){
  
    html.obj &lt;- read_html(u)
    title &lt;- html.obj %&gt;% html_nodes('a.storylink') %&gt;% html_text()
    score &lt;- html.obj %&gt;% html_nodes('span.score') %&gt;% html_text()
  
   data.frame(title = title, score = score)
  })
  
  
  library(reshape)
  data &lt;- merge_recurse(df)
  
  View(data)
  </code></pre>
  
  <p>However, when I try this, the output does not properly populate the URLs variable, and so the rest of the looped data gathering does not execute at all.</p>
  
  <p>I haven't been able to find any other questions here that cover the looping through concatenated items like this.</p>
  
  <p>Can someone provide an idea of where I am going wrong?</p>