Count number of entries in sqlite3 database tables

bike_db_totals(bikedb, trips = TRUE, city)

Arguments

bikedb

A string containing the path to the SQLite3 database.

trips

If true, numbers of trips are counted; otherwise numbers of stations

city

Optional city for which numbers of trips are to be counted

Examples

data_dir <- tempdir () bike_write_test_data (data_dir = data_dir) bikedb <- file.path (data_dir, 'testdb') store_bikedata (data_dir = data_dir, bikedb = bikedb)
#> Creating sqlite3 database
#> Unzipping raw data files for bo ...
#> Reading files for bo ...
#> reading file 1/3: /tmp/Rtmp88OwDl/hubway_Trips_2012.csv #> reading file 2/3: /tmp/Rtmp88OwDl/201701-hubway-tripdata.csv #> reading file 3/3: /tmp/Rtmp88OwDl/201801_hubway_tripdata.csv
#> Trips read for bo = 600
#> Unzipping raw data files for ch ...
#> Reading files for ch ...
#> reading file 1/1: /tmp/Rtmp88OwDl/Divvy_Trips_sample.csv
#> Trips read for ch = 200
#> Unzipping raw data files for dc ...
#> Reading files for dc ...
#> reading file 1/1: /tmp/Rtmp88OwDl/2017Q1-capitalbikeshare-tripdata-temp.csv
#> Trips read for dc = 200
#> Unzipping raw data files for la ...
#> Reading files for la ...
#> reading file 1/1: /tmp/Rtmp88OwDl/la_metro_gbfs_trips_Q1_2017.csv
#> Trips read for la = 198
#> Reading files for lo ...
#> getting london stations ...
#> done
#> reading file 1/1: /tmp/Rtmp88OwDl/01aJourneyDataExtract10Jan16-23Jan16.csv
#> Trips read for lo = 200
#> Unzipping raw data files for mn ...
#> Reading files for mn ...
#> reading file 1/1: /tmp/Rtmp88OwDl/Nice_Ride_trip_history_2012_season.csv
#> Trips read for mn = 200
#> Unzipping raw data files for ny ...
#> Reading files for ny ...
#> reading file 1/1: /tmp/Rtmp88OwDl/201612-citibike-tripdata.csv
#> Trips read for ny = 200
#> Total trips read = 1,798
#> [1] 1798
# create database indexes for quicker access: index_bikedata_db (bikedb = bikedb) bike_db_totals (bikedb = bikedb, trips = TRUE) # total trips
#> [1] 1798
bike_db_totals (bikedb = bikedb, trips = TRUE, city = 'ch')
#> [1] 200
bike_db_totals (bikedb = bikedb, trips = TRUE, city = 'ny')
#> [1] 200
bike_db_totals (bikedb = bikedb, trips = FALSE) # total stations
#> [1] 2593
bike_db_totals (bikedb = bikedb, trips = FALSE, city = 'ch')
#> [1] 581
bike_db_totals (bikedb = bikedb, trips = FALSE, city = 'ny')
#> [1] 233
# numbers of stations can also be extracted with nrow (bike_stations (bikedb = bikedb))
#> [1] 2593
nrow (bike_stations (bikedb = bikedb, city = 'ch'))
#> [1] 581
bike_rm_test_data (data_dir = data_dir)
#> [1] 13
bike_rm_db (bikedb)
#> [1] TRUE
# don't forget to remove real data! # file.remove (list.files ('.', pattern = '.zip'))