title: Make a SpatialPointsDataFrame with sf the fast way
body: <p>The task I'm trying to do is very simple with the <code>sp</code> package in R but I'm trying to learn <code>sf</code> hence my question.  I'm trying to create a shape of points in R.  I have lots of points so it has to be efficient.  I've succeeded doing it in both <code>sp</code> and <code>sf</code> but the sf method is slow.  Being new to <code>sf</code>, I have a feeling I'm not doing it the most efficient way.  </p>
  
  <p>I've made 3 different functions which do the same thing:</p>
  
  <p>1) 100% <code>sp</code></p>
  
  <pre><code>f_rgdal &lt;- function(dat) {
    coordinates(dat) &lt;- ~x+y
  }
  </code></pre>
  
  <p>2) 100% <code>sf</code> (probably bad...)</p>
  
  <pre><code>f_sf &lt;- function(dat) {
    dat &lt;- st_sfc(
      lapply(
        apply(dat[,c("x", "y")], 1, list), function(xx) st_point(xx[[1]])
        )
      )
  }
  </code></pre>
  
  <p>3) mix of both:</p>
  
  <pre><code>f_rgdal_sp &lt;- function(dat) {
    coordinates(dat) &lt;- ~x+y
    dat &lt;- as(dat, "sf")
  }
  </code></pre>
  
  <p>If I benchmark them, you can see that both function 2 and 3 are way slower than function 1:</p>
  
  <pre><code>set.seed(1234)
  dd &lt;- data.frame(x = runif(nb_pt, 0, 100),
                   y = runif(nb_pt, 0,50),
                   f1 = rnorm(nb_pt))
  
  library(sp)
  library(sf)
  library(rbenchmark)
  benchmark(f_rgdal(dd), f_sf(dd), f_rgdal_sp(dd), columns = c("test", "elapsed"))
              test elapsed
  1    f_rgdal(dd)    0.22
  3 f_rgdal_sp(dd)    4.82
  2       f_sf(dd)    4.08
  </code></pre>
  
  <p>Is their a way to speed up <code>sf</code>?  At the end, I want to use <code>st_write</code> which is faster then <code>writeOGR</code> so staying in <code>sp</code> is not ideal.</p>