title: r - add multiple markers to rMaps
body: <p><strong>Question</strong></p>
  
  <p>How do you add multiple markers using <a href="https://github.com/ramnathv/rMaps" rel="nofollow noreferrer"><code>rMaps</code></a>?</p>
  
  <p><strong>Data</strong></p>
  
  <pre><code>coords &lt;- structure(list(stop_id = 19841:19843, stop_name = c("Flagstaff Railway Station (Melbourne City)", 
  "Melbourne Central Railway Station (Melbourne City)", "Parliament Railway Station (Melbourne City)"
  ), stop_lat = c(-37.8119813073807, -37.8099387667386, -37.8110540555305
  ), stop_lon = c(144.955653760429, 144.962593535096, 144.972910916416
  )), .Names = c("stop_id", "stop_name", "stop_lat", "stop_lon"
  ), sorted = "stop_id", row.names = 17:19, class = c("data.table", 
  "data.frame"))
  </code></pre>
  
  <p><strong>Examples</strong></p>
  
  <p>Using <code>library(rMaps)</code> I can create a map and add a single marker, as per the examples on Ramnath's github page:</p>
  
  <pre><code>library(rMaps)
  
  l &lt;- Leaflet$new()
  l$setView(c(-37.8602828, 145.079616), zoom=11)
  l$tileLayer(provider = "Acetate.terrain")
  
  ## add one marker:
  l$marker(LatLng = c(-37.81198,144.9557))
  </code></pre>
  
  <p>But I can't figure out how to add multiple markers from the <code>coords</code> data frame, without writing a <code>l$marker</code> line for each one.</p>
  
  <p>I've tried to use <code>GeoJSON</code> but I'm new to this so haven't got my head around it yet and must be doing something wrong.</p>
  
  <pre><code># library(rgdal)
  # coords.sp &lt;- SpatialPointsDataFrame(coords[,.(stop_lon, stop_lat)], coords[,.(stop_id, stop_name)])
  # writeOGR(obj=coords.sp, dsn='coords.geojson', layer='OGRGeoJSON', driver='GeoJSON')
  
  # gj &lt;- readOGR("./coords.geojson", layer="OGRGeoJSON")
  # l$geoJson(gj)
  # l$geoJson("./coords.geojson")
  </code></pre>
  
  <p>I'm happy to use <code>JSON/GeoJSON</code> if it's the way to go.</p>
  
  <p><strong>Desired output</strong></p>
  
  <p>I would like the result to be the same as if I used <code>library(leaflet)</code> to show multiple markers</p>
  
  <pre><code>library(leaflet)
  leaflet() %&gt;%
    addProviderTiles("Acetate.terrain") %&gt;%
    setView(lat = -37.8602828, lng = 145.079616, zoom=11) %&gt;%
    addMarkers(data=coords, lat=~stop_lat, lng=~stop_lon)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/sKc17.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sKc17.jpg" alt="marker_example"></a></p>
  
  <p><strong>GeoJSON</strong></p>
  
  <p>Here is the GeoJSON code that's produced from the <code>writeOGR</code> command, and I've validated it <a href="http://geojsonlint.com/" rel="nofollow noreferrer">at GeoJSONLint</a></p>
  
  <pre><code>{
  "type": "FeatureCollection",
  
  "features": [
  { "type": "Feature", "id": 1, "properties": { "stop_id": 19841, "stop_name": "Flagstaff Railway Station (Melbourne City)" }, "geometry": { "type": "Point", "coordinates": [ 144.955653760428987, -37.811981307380698 ] } },
  { "type": "Feature", "id": 2, "properties": { "stop_id": 19842, "stop_name": "Melbourne Central Railway Station (Melbourne City)" }, "geometry": { "type": "Point", "coordinates": [ 144.962593535096005, -37.809938766738597 ] } },
  { "type": "Feature", "id": 3, "properties": { "stop_id": 19843, "stop_name": "Parliament Railway Station (Melbourne City)" }, "geometry": { "type": "Point", "coordinates": [ 144.972910916415998, -37.811054055530498 ] } }
  ]}
  </code></pre>