-
Notifications
You must be signed in to change notification settings - Fork 17
/
README.Rmd
208 lines (179 loc) · 8.41 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
---
title: "bikedata"
keywords: "bicycle hire systems, bike hire systems, bike hire, bicycle hire, database, bike data"
output:
rmarkdown::html_vignette:
self_contained: no
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
[![R build status](https://github.com/ropensci/bikedata/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/bikedata/actions?query=workflow%3AR-CMD-check)
[![codecov](https://codecov.io/gh/ropensci/bikedata/branch/master/graph/badge.svg)](https://codecov.io/gh/ropensci/bikedata)
[![Project Status: Active](http://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/bikedata)](https://cran.r-project.org/package=bikedata)
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/grand-total/bikedata?color=orange)](https://cran.r-project.org/package=bikedata)
[![](http://badges.ropensci.org/116_status.svg)](https://github.com/ropensci/software-review/issues/116)
[![status](https://joss.theoj.org/papers/10.21105/joss.00471/status.svg)](https://joss.theoj.org/papers/10.21105/joss.00471)
The `bikedata` package aims to enable ready importing of historical trip data
from all public bicycle hire systems which provide data, and will be expanded on
an ongoing basis as more systems publish open data. Cities and names of
associated public bicycle systems currently included, along with numbers of
bikes and of docking stations (from
[wikipedia](https://en.wikipedia.org/wiki/List_of_bicycle-sharing_systems#Cities)),
are
City | Hire Bicycle System | Number of Bicycles | Number of Docking Stations
--- | --- | --- | ---
London, U.K. | [Santander Cycles](https://tfl.gov.uk/modes/cycling/santander-cycles) | 13,600 | 839
San Francisco Bay Area, U.S.A. | [Ford GoBike](https://www.fordgobike.com/) | 7,000 | 540
New York City NY, U.S.A. | [citibike](https://www.citibikenyc.com/) | 7,000 | 458
Chicago IL, U.S.A. | [Divvy](https://www.divvybikes.com/) | 5,837 | 576
Montreal, Canada | [Bixi](https://bixi.com/) | 5,220 | 452
Washingon DC, U.S.A. | [Capital BikeShare](https://www.capitalbikeshare.com/) | 4,457 | 406
Guadalajara, Mexico | [mibici](https://www.mibici.net/) | 2,116 | 242
Minneapolis/St Paul MN, U.S.A. | [Nice Ride](https://www.niceridemn.com/) | 1,833 | 171
Boston MA, U.S.A. | [Hubway](https://www.bluebikes.com/) | 1,461 | 158
Philadelphia PA, U.S.A. | [Indego](https://www.rideindego.com) | 1,000 | 105
Los Angeles CA, U.S.A. | [Metro](https://bikeshare.metro.net/) | 1,000 | 65
These data include the places and times at which all trips start and end. Some
systems provide additional demographic data including years of birth and genders
of cyclists. The list of cities may be obtained with the `bike_cities()`
functions, and details of which include demographic data with
`bike_demographic_data()`.
The following provides a brief overview of package functionality. For more
detail, see the
[vignette](https://docs.ropensci.org/bikedata/articles/bikedata.html).
------
## 1 Installation
Currently a development version only which can be installed with the following
command,
```{r, eval=FALSE}
devtools::install_github("ropensci/bikedata")
```
```{r usage2, echo=FALSE, message=FALSE}
devtools::load_all (".")
#devtools::load_all (".", recompile=TRUE)
#devtools::document (".")
#goodpractice::gp ("bikedata")
#devtools::check (".")
#testthat::test_dir ("./tests/")
#Rcpp::compileAttributes()
```
and then loaded the usual way
```{r, eval = FALSE}
library (bikedata)
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width = 120)
```
## 2 Usage
Data may downloaded for a particular city and stored in an `SQLite3` database
with the simple command,
```{r, echo = FALSE, eval = FALSE}
dl_bikedata (city = 'ny', data_dir = '/data/data/bikes/nyc-temp/',
dates = 201601:201603)
store_bikedata (bikedb = 'bikedb', data_dir = '/data/data/bikes/nyc-temp/')
```
```{r, eval = FALSE}
store_bikedata (city = 'nyc', bikedb = 'bikedb', dates = 201601:201603)
# [1] 2019513
```
where the `bikedb` parameter provides the name for the database, and the
optional argument `dates` can be used to specify a particular range of dates
(Jan-March 2016 in this example). The `store_bikedata` function returns the
total number of trips added to the specified database. The primary objects
returned by the `bikedata` packages are 'trip matrices' which contain aggregate
numbers of trips between each pair of stations. These are extracted from the
database with:
```{r, eval = FALSE}
tm <- bike_tripmat (bikedb = 'bikedb')
dim (tm); format (sum (tm), big.mark = ',')
```
```{r, echo = FALSE}
c (518, 518)
"2,019,513"
```
During the specified time period there were just over 2 million trips between
518 bicycle docking stations. Note that the associated databases can be very
large, particularly in the absence of `dates` restrictions, and extracting these
data can take quite some time.
Data can also be aggregated as daily time series with
```{r, eval = FALSE}
bike_daily_trips (bikedb = 'bikedb')
```
```{r, echo = FALSE}
n <- 87
dates <- c ('2016-01-01', '2016-01-02', '2016-01-03', '2016-01-04',
'2016-01-05', '2016-01-06', '2016-01-07', '2016-01-08',
'2016-01-08', '2016-01-10', rep (NA, n - 10))
nt <- c (11172, 14794, 15775, 19879, 18326, 24922, 28215, 29131, 21140, 14481,
rep (NA, n - 10))
tibble::tibble (date = dates, numtrips = nt)
```
A summary of all data contained in a given database can be produced as
```{r, eval = FALSE}
bike_summary_stats (bikedb = 'bikedb')
#> num_trips num_stations first_trip last_trip latest_files
#> ny 2019513 518 2016-01-01 00:00 2016-03-31 23:59 FALSE
```
The final field, `latest_files`, indicates whether the files in the database are
up to date with the latest published files.
### 2.1 Filtering trips by dates, times, and weekdays
Trip matrices can be constructed for trips filtered by dates, days of the week,
times of day, or any combination of these. The temporal extent of a `bikedata`
database is given in the above `bike_summary_stats()` function, or can be
directly viewed with
```{r, eval = FALSE}
bike_datelimits (bikedb = 'bikedb')
```
```{r, echo = FALSE}
res <- c ("2016-01-01 00:00", "2016-03-31 23:59")
names (res) <- c ("first", "last")
res
```
Additional temporal arguments which may be passed to the `bike_tripmat`
function include `start_date`, `end_date`, `start_time`, `end_time`, and
`weekday`. Dates and times may be specified in almost any format, but larger
units must always precede smaller units (so years before months before days;
hours before minutes before seconds). The following examples illustrate the
variety of acceptable formats for these arguments.
```{r, eval = FALSE}
tm <- bike_tripmat ('bikedb', start_date = "20160102")
tm <- bike_tripmat ('bikedb', start_date = 20160102, end_date = "16/02/28")
tm <- bike_tripmat ('bikedb', start_time = 0, end_time = 1) # 00:00 - 01:00
tm <- bike_tripmat ('bikedb', start_date = 20160101, end_date = "16,02,28",
start_time = 6, end_time = 24) # 06:00 - 23:59
tm <- bike_tripmat ('bikedb', weekday = 1) # 1 = Sunday
tm <- bike_tripmat ('bikedb', weekday = c('m', 'Th'))
tm <- bike_tripmat ('bikedb', weekday = 2:6,
start_time = "6:30", end_time = "10:15:25")
```
### 2.2 Filtering trips by demographic characteristics
Trip matrices can also be filtered by demographic characteristics through
specifying the three additional arguments of `member`, `gender`, and
`birth_year`. `member = 0` is equivalent to `member = FALSE`, and `1` equivalent
to `TRUE`. `gender` is specified numerically such that values of `2`, `1`, and
`0` respectively translate to female, male, and unspecified. The following lines
demonstrate this functionality
```{r, eval = FALSE}
sum (bike_tripmat ('bikedb', member = 0))
sum (bike_tripmat ('bikedb', gender = 'female'))
sum (bike_tripmat ('bikedb', weekday = 'sat', birth_year = 1980:1990,
gender = 'unspecified'))
```
### 3. Citation
```{r}
citation ("bikedata")
```
### 4. Code of Conduct
Please note that this project is released with a [Contributor Code of
Conduct](https://ropensci.org/code-of-conduct/). By contributing to this
project you agree to abide by its terms.
[![ropensci\_footer](https://ropensci.org//public_images/github_footer.png)](https://ropensci.org/)