diff --git a/.Rproj.user/shared/notebooks/37C2766F-descriptives02/1/s/lib/HomeButton-0.0.1/LICENSE b/.Rproj.user/shared/notebooks/37C2766F-descriptives02/1/s/lib/HomeButton-0.0.1/LICENSE deleted file mode 100644 index a1d3414..0000000 --- a/.Rproj.user/shared/notebooks/37C2766F-descriptives02/1/s/lib/HomeButton-0.0.1/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright (C) 2014 Daniel Montague - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/.gitignore b/.gitignore index 5532d33..1315e0d 100644 --- a/.gitignore +++ b/.gitignore @@ -82,3 +82,4 @@ # password or passwords are also ignored. NOTE that your project might be # using different names and then you must edit the lines below accordingly. +.Rproj.user diff --git a/code/sandbox-json.R b/code/sandbox-json.R new file mode 100644 index 0000000..9495272 --- /dev/null +++ b/code/sandbox-json.R @@ -0,0 +1,71 @@ +# sandbox-json.R +# a sandbox for accessing system data from https://gbfs.capitalbikeshare.com/gbfs/gbfs.json +library(jsonlite) +library(dplyr) +library(mapview) +library(leaflet) +library(sf) + + +url_stations <- "https://gbfs.capitalbikeshare.com/gbfs/en/station_information.json" +url_regions <- "https://gbfs.capitalbikeshare.com/gbfs/en/system_regions.json" +url_freebikes <- "https://gbfs.capitalbikeshare.com/gbfs/en/free_bike_status.json" + +json_stations <- fromJSON(url_stations) +json_regions <- fromJSON(url_regions) +json_freebikes <- fromJSON(url_freebikes) + +stations <- json_stations$data$stations +regions <- json_regions$data$regions +freebikes <- json_freebikes$data$bikes + +# is legacy_id same as station_id? +stations %>% + mutate(same = (legacy_id == station_id)) %>% + count(same) + # yes + +# freebikes appears to have locations of current undocked electric bikes + +leaflet() %>% + addTiles() %>% + addCircleMarkers(data = freebikes, + lat = ~lat, + lng = ~lon, + label = ~type) %>% + addCircleMarkers(data = stations, + radius = 5, + color = "#000", + lat = ~lat, + lng = ~lon, + label = ~name) + +# highlight bikes that are not within 200m of a station +stations_sf <- st_as_sf(stations, + coords = c("lon", "lat"), + crs = st_crs(4326)) %>% + select(station_id, name, region_id, capacity) + +freebikes_sf <- st_as_sf(freebikes, + coords = c("lon", "lat"), + crs = st_crs(4326)) + + +close <- + st_join(freebikes_sf, # left side = freebikes + stations_sf, # right side = stations + join = st_is_within_distance, # join type + left = TRUE, # keep all obs from station key + dist = 200, + suffix = c(".x", ".y"), + largest = FALSE) %>% + mutate(close = !is.na(station_id)) %>% + select(bike_id, close, is_disabled, is_reserved, station_id, name.y) + # note this produces duplicates of bike_id + + + +mapviewOptions(fgb = FALSE) # fix error https://github.com/r-spatial/mapview/issues/412 + +mapview(stations_sf, label = "name") + + mapview(close, zcol = "close", col.regions = c("red", "green")) diff --git a/renv.lock b/renv.lock index 3c20689..d6f09a6 100644 --- a/renv.lock +++ b/renv.lock @@ -1498,7 +1498,9 @@ "Source": "Repository", "Repository": "CRAN", "Hash": "b37932b67288bc62bb81686b2f337a7d", - "Requirements": [] + "Requirements": [ + "remotes" + ] }, "padr": { "Package": "padr", @@ -1836,6 +1838,14 @@ "tibble" ] }, + "remotes": { + "Package": "remotes", + "Version": "2.4.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "227045be9aee47e6dda9bb38ac870d67", + "Requirements": [] + }, "renv": { "Package": "renv", "Version": "0.15.2",