Extract date-time limits from trip database

bike_datelimits(bikedb, city)

Arguments

bikedb

A string containing the path to the SQLite3 database. If no directory specified, it is presumed to be in tempdir().

city

If given, date limits are calculated only for trips in that city.

Value

A vector of 2 elements giving the date-time of the first and last trips

Examples

data_dir <- tempdir () bike_write_test_data (data_dir = data_dir) # dl_bikedata (city = 'la', data_dir = data_dir) # or download some real data! # Remove one London file that triggers an API call which may fail tests: file.remove (file.path (tempdir(), "01aJourneyDataExtract10Jan16-23Jan16.csv"))
#> [1] TRUE
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
#> 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,598
#> [1] 1598
# create database indexes for quicker access: index_bikedata_db (bikedb = bikedb) bike_datelimits ('testdb') # overall limits for all cities
#> first last #> "2012-04-02 13:07:00" "2018-01-02 07:02:04"
bike_datelimits ('testdb', city = 'NYC')
#> first last #> "2016-12-01 00:00:04" "2016-12-01 01:33:37"
bike_datelimits ('testdb', city = 'los angeles')
#> first last #> "2017-01-01 00:15:00" "2017-01-01 16:55:00"
bike_rm_test_data (data_dir = data_dir)
#> [1] 12
bike_rm_db (bikedb)
#> [1] TRUE
# don't forget to remove real data! # file.remove (list.files ('.', pattern = '.zip'))