reprex_reprex.utf8.md

      library(quadmesh)
    library(raster)
    #> Loading required package: sp
    library(sf)
    #> Linking to GEOS 3.6.2, GDAL 2.3.2, PROJ 4.9.3
    library(lwgeom)
    #> Linking to liblwgeom 2.5.0dev r16016, GEOS 3.6.2, proj.4 4.9.3
    library(reproj)
    library(rgdal)
    #> rgdal: version: 1.3-6, (SVN revision 773)
    #>  Geospatial Data Abstraction Library extensions to R successfully loaded
    #>  Loaded GDAL runtime: GDAL 2.3.2, released 2018/09/21
    #>  Path to GDAL shared files: /usr/local/share/gdal
    #>  GDAL binary built with GEOS: TRUE
    #>  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
    #>  Path to PROJ.4 shared files: (autodetected)
    #>  Linking to sp version: 1.3-1
    xy <- coordinates(etopo)

    ## we want "p_?" the matrix of coordinates in LAEA
    ll <- "+proj=longlat +datum=WGS84"
    prj <- "+proj=laea +datum=WGS84"

    mpt <- st_sfc(st_multipoint(xy), crs = ll)
    pt <- st_sfc(lapply(split(t(xy), rep(seq_len(nrow(xy)), each = 2)), st_point), crs = ll)
    library(bench)

    a <- bench::mark(
                lwgeom_mpt = st_coordinates(st_transform_proj(mpt, prj))[, 1:2, drop = FALSE],   # 0.147s
                reproj = reproj(xy, target = prj, source = ll)[, 1:2, drop = FALSE],             # 0.021s
                lwgeom_pt = st_coordinates(st_transform(pt, prj))[, 1:2, drop = FALSE],          # 2.36s
                rgdal = rgdal::project(xy, prj),                                                 # 0.019s
                iterations = 20,
                check = FALSE)
    #> Warning: Some expressions had a GC in every iteration; so filtering is
    #> disabled.

    library(dplyr)
    #>
    #> Attaching package: 'dplyr'
    #> The following objects are masked from 'package:raster':
    #>
    #>     intersect, select, union
    #> The following objects are masked from 'package:stats':
    #>
    #>     filter, lag
    #> The following objects are masked from 'package:base':
    #>
    #>     intersect, setdiff, setequal, union
    a %>% select(expression, median, `itr/sec`, mem_alloc, total_time) %>% arrange(desc(total_time))
    #> # A tibble: 4 x 5
    #>   expression   median `itr/sec` mem_alloc total_time
    #>   <chr>      <bch:tm>     <dbl> <bch:byt>   <bch:tm>
    #> 1 lwgeom_pt     2.02s     0.488    19.7MB     41.01s
    #> 2 lwgeom_mpt  139.8ms     6.99    12.11MB      2.86s
    #> 3 rgdal       19.43ms    30.8      5.07MB   648.58ms
    #> 4 reproj      21.61ms    40.1     11.53MB   499.12ms

Created on 2018-12-19 by the reprex package (v0.2.1)