Title: | Get City Bike Data from Norway |
---|---|
Description: | Functions to get and download city bike data from the website and API service of each city bike service in Norway. The package aims to reduce time spent on getting Norwegian city bike data, and lower barriers to start analyzing it. The data is retrieved from Oslo City Bike, Bergen City Bike, and Trondheim City Bike. The data is made available under NLOD 2.0 <https://data.norge.no/nlod/en/2.0>. |
Authors: | Iman Ghayoornia [aut, cre] |
Maintainer: | Iman Ghayoornia <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.1 |
Built: | 2025-03-11 03:29:46 UTC |
Source: | https://github.com/imangr/bysykkel |
dl_trips_data
downloads a file of anonymized historical bike
trips data in Norway for the city of Oslo, Bergen, and Trondheim.
The data is provided according to the Norwegian License for Open Government Data 2.0 NLOD 2.0.
The data is downloaded from:
dl_trips_data(year, month, city, filetype = "CSV")
dl_trips_data(year, month, city, filetype = "CSV")
year |
A number. The year that you want to download data for. |
month |
A number. The month that you want to download data for. |
city |
A string. The city that you want to download data for. The options are "Oslo", "Bergen", and "Trondheim". |
filetype |
A string. The filetype that you want to download data for. The options are "CSV" (default) and "JSON". |
The function downloads a CSV-file to your current working directory.
## Not run: # Download bike trip data for the month of January, 2019, in Bergen # as CSV or JSON dl_trips_data(year = 2019, month = 01, city = "Bergen", filetype = "CSV) dl_trips_data(year = 2019, month = 01, city = "Bergen", filetype = "JSON) # Download bike trips data for the month of October, 2018, in Trondheim dl_trips_data(2018, 10, "Trondheim") # Use "lapply()" to download bike trips data for several months in Oslo lapply(06:08, dl_trips_data, year = 2018, city = "Oslo") ## End(Not run)
## Not run: # Download bike trip data for the month of January, 2019, in Bergen # as CSV or JSON dl_trips_data(year = 2019, month = 01, city = "Bergen", filetype = "CSV) dl_trips_data(year = 2019, month = 01, city = "Bergen", filetype = "JSON) # Download bike trips data for the month of October, 2018, in Trondheim dl_trips_data(2018, 10, "Trondheim") # Use "lapply()" to download bike trips data for several months in Oslo lapply(06:08, dl_trips_data, year = 2018, city = "Oslo") ## End(Not run)
fread_trips_data()
imports anonymized historical bike trips data for
the city of Oslo, Bergen, and Trondheim, in Norway, directly to R.
fread_trips_data()
utilizes the
fread()
function from the data.table
package to fast read the CSV-files. Hence, it is much faster than
read_trips_data
. fread_trips_data()
requires that you
have the data.table
package installed.
The data is provided according to the Norwegian License for Open Government Data 2.0 (NLOD 2.0).
The data is read from:
fread_trips_data(year, month, city)
fread_trips_data(year, month, city)
year |
A number. The year that you want to download data for. |
month |
A number. The month that you want to download data for. |
city |
A string. The city you want to download data from. The options are "Oslo", "Bergen", and "Trondheim". |
The function reads in bike trips data for the specified year, month, and city to R as a tibble.
## Not run: # Fast read bike trips data for the month of January 2019 in Bergen bergen_trips <- fread_trips_data(year = 2019, month = 1, city = "Bergen") # Fast read bike trips data for the month of October 2018 in Trondheim trondheim_trips <- fread_trips_data(2018, 10, "Trondheim") ## End(Not run)
## Not run: # Fast read bike trips data for the month of January 2019 in Bergen bergen_trips <- fread_trips_data(year = 2019, month = 1, city = "Bergen") # Fast read bike trips data for the month of October 2018 in Trondheim trondheim_trips <- fread_trips_data(2018, 10, "Trondheim") ## End(Not run)
get_api_data
gets real-time data on bike availability, stations, and
system from the API for
Please read the API documentation for each City Bike API before using this function.
The real-time data is provided in the GBFS (General Bikeshare Feed Specification) format, which you can read more about on here.
The data is provided according to the Norwegian License for Open Government Data 2.0 NLOD 2.0.
get_api_data(client_id, data, city, return_df = FALSE)
get_api_data(client_id, data, city, return_df = FALSE)
client_id |
A string. The string should represent a client identifier to access the
API. The client identifier must be of the form |
data |
A string. The data that you want to get from the API. The options are "availability", "stations", and "system". |
city |
A string. The city, or city bike service API, that you want to get data from. The options are "Oslo", "Bergen", or "Trondheim". |
return_df |
Either |
If return_df = FALSE
, then the function returns a list
that
contains two elements: a data frame with the
"main" data, and the datetime (POSIX) for the API request. If
return_df = TRUE
, then the function returns only a tibble.
## Not run: # Get data on bike "availability" oslo_api_data <- get_api_data(client_id = "mycompany-myservice", data = "availability", city = "Oslo") # Get data on bike "availability", but return a tibble oslo_winter_bike <- get_api_data(client_id = "myname-myapp", data = "availability", city = "Oslo", return_df = TRUE) ## End(Not run)
## Not run: # Get data on bike "availability" oslo_api_data <- get_api_data(client_id = "mycompany-myservice", data = "availability", city = "Oslo") # Get data on bike "availability", but return a tibble oslo_winter_bike <- get_api_data(client_id = "myname-myapp", data = "availability", city = "Oslo", return_df = TRUE) ## End(Not run)
read_trips_data
imports anonymized historical bike trips data in
Norway for the city of Oslo, Bergen, and Trondheim directly to R.
The data is provided according to the Norwegian License for Open Government Data 2.0 NLOD 2.0.
The data is read from:
read_trips_data(year, month, city)
read_trips_data(year, month, city)
year |
A number. The year that you want to download data for. |
month |
A number. The month that you want to download data for. |
city |
A string. The city you want to download data from. The options are "Oslo", "Bergen", and "Trondheim". |
The function reads in bike trips data for the specified year, month, and city to R as a tibble.
## Not run: # Read bike trips data for the month of January 2019 in Bergen bergen_trips <- read_trips_data(2019, 1, "Bergen") # Read bike trips data for the month of October 2018 in Trondheim trondheim_trips <- read_trips_data(2018, 10, "Trondheim") ## End(Not run)
## Not run: # Read bike trips data for the month of January 2019 in Bergen bergen_trips <- read_trips_data(2019, 1, "Bergen") # Read bike trips data for the month of October 2018 in Trondheim trondheim_trips <- read_trips_data(2018, 10, "Trondheim") ## End(Not run)