Package 'bysykkel'

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

Help Index


Download historical bike trips data in Norway

Description

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:

Usage

dl_trips_data(year, month, city, filetype = "CSV")

Arguments

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".

Value

The function downloads a CSV-file to your current working directory.

Examples

## 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)

Fast read historical bike trips data in Norway to R

Description

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:

Usage

fread_trips_data(year, month, city)

Arguments

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".

Value

The function reads in bike trips data for the specified year, month, and city to R as a tibble.

Examples

## 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 real-time data from the city bike APIs in Norway

Description

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.

Usage

get_api_data(client_id, data, city, return_df = FALSE)

Arguments

client_id

A string. The string should represent a client identifier to access the API. The client identifier must be of the form "myname-myapp" or "mycompany-myservice", such that the city bike service knows who is accessing the API, and for what purpose(s). Please visit the website of the API service that you want to access to learn how to correctly specify the client_id.

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 TRUE or FALSE. Instructs the function on whether to return only a tibble (if set to TRUE).

Value

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.

Examples

## 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 historical bike trips data in Norway to R

Description

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:

Usage

read_trips_data(year, month, city)

Arguments

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".

Value

The function reads in bike trips data for the specified year, month, and city to R as a tibble.

Examples

## 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)