Skip to content

Commit

Permalink
Merge pull request #218 from r-transit/dev/reduce_package_size
Browse files Browse the repository at this point in the history
Reduce package file size
  • Loading branch information
polettif authored Oct 18, 2024
2 parents daf446f + cbb693a commit af395fb
Show file tree
Hide file tree
Showing 29 changed files with 55 additions and 54 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- `read_gtfs()` can now read `locations.geojson` files according to the updated specifications [#214](https://github.com/r-transit/tidytransit/pull/214)
- tidytransit 1.7.0 needs `gtfsio` 1.2.0 as it uses json reading capabilities from `gtfsio::import_gtfs()`
- Internally, the automatically parsed specifications from https://gtfs.org/documentation/schedule/reference/ are now used
- The example feed `google_transit_nyc_subway.zip` has been modified and renamed to `nyc_subway.zip` [#218](https://github.com/r-transit/tidytransit/pull/218)


# tidytransit 1.6.1
Expand Down
2 changes: 1 addition & 1 deletion R/filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @export
#' @examples \donttest{
#' library(dplyr)
#' local_gtfs_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
#' local_gtfs_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
#' nyc <- read_gtfs(local_gtfs_path)
#' select_service_id <- filter(nyc$calendar, monday==1) %>% pull(service_id)
#' select_route_id <- sample_n(nyc$routes, 1) %>% pull(route_id)
Expand Down
6 changes: 3 additions & 3 deletions R/geo.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' \dontrun{
#' library(dplyr)
#'
#' nyc_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
#' nyc_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
#' nyc <- read_gtfs(nyc_path)
#'
#' nyc$stops %>%
Expand Down Expand Up @@ -103,7 +103,7 @@ prep_dist_mtrx = function(dist_list) {
#' \dontrun{
#' library(dplyr)
#'
#' nyc_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
#' nyc_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
#' nyc <- read_gtfs(nyc_path)
#'
#' stop_group_distances(nyc$stops)
Expand Down Expand Up @@ -185,7 +185,7 @@ stop_group_distances = function(gtfs_stops, by = "stop_name") {
#' @importFrom stats kmeans
#' @examples \donttest{
#' library(dplyr)
#' nyc_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
#' nyc_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
#' nyc <- read_gtfs(nyc_path)
#' nyc <- cluster_stops(nyc)
#'
Expand Down
2 changes: 1 addition & 1 deletion R/io.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @seealso [validate_gtfs()], [write_gtfs()]
#'
#' @examples \dontrun{
#' local_gtfs_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
#' local_gtfs_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
#' gtfs <- read_gtfs(local_gtfs_path)
#' summary(gtfs)
#'
Expand Down
2 changes: 1 addition & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @examples \donttest{
#' local_gtfs_path <- system.file("extdata",
#' "google_transit_nyc_subway.zip",
#' "nyc_subway.zip",
#' package = "tidytransit")
#' nyc <- read_gtfs(local_gtfs_path)
#' plot(nyc)
Expand Down
2 changes: 1 addition & 1 deletion R/raptor.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#' @import data.table
#' @export
#' @examples \donttest{
#' nyc_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
#' nyc_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
#' nyc <- read_gtfs(nyc_path)
#'
#' # you can use initial walk times to different stops in walking distance (arbitrary example values)
Expand Down
2 changes: 1 addition & 1 deletion R/summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @examples \dontrun{
#' path = system.file("extdata",
#' "google_transit_nyc_subway.zip",
#' "nyc_subway.zip",
#' package = "tidytransit")
#'
#' g = read_gtfs(path)
Expand Down
2 changes: 1 addition & 1 deletion R/travel_times.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#'
#' # 2) separate filtering and travel time calculation for a more granular analysis
#' # stop_names in this feed are not restricted to an area, create clusters of stops to fix
#' nyc_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
#' nyc_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
#' nyc <- read_gtfs(nyc_path)
#' nyc <- cluster_stops(nyc, group_col = "stop_name", cluster_colname = "stop_name")
#'
Expand Down
2 changes: 1 addition & 1 deletion R/validate_gtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#' #> # 2 more variables: validation_status <chr>, validation_details <chr>
#'
#' \dontrun{
#' local_gtfs_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
#' local_gtfs_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
#' gtfs <- read_gtfs(local_gtfs_path)
#' attr(gtfs, "validation_result")
#'
Expand Down
Binary file removed inst/extdata/google_transit_nyc_subway.zip
Binary file not shown.
Binary file added inst/extdata/nyc_subway.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion man/cluster_stops.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/filter_stops.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot.tidygtfs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/print.tidygtfs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/raptor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/read_gtfs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/stop_distances.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/stop_group_distances.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/travel_times.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/validate_gtfs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-read-gtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_that("read_gtfs() imports a local file to a list of

test_that("reading a real feed", {
skip_on_cran()
g_nyc_path = system.file("extdata", "google_transit_nyc_subway.zip",
g_nyc_path = system.file("extdata", "nyc_subway.zip",
package = "tidytransit")
gtfs_obj = read_gtfs(g_nyc_path)

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ test_that("stop_group_distances", {

test_that("stop_group_distances real feed", {
skip_on_cran()
g_nyc = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit"))
g_nyc = read_gtfs(system.file("extdata", "nyc_subway.zip", package = "tidytransit"))

x1 = stop_group_distances(g_nyc$stops)

Expand All @@ -170,7 +170,7 @@ test_that("stop_group_distances real feed", {
test_that("stops cluster", {
skip_on_cran()

g_nyc = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit"))
g_nyc = read_gtfs(system.file("extdata", "nyc_subway.zip", package = "tidytransit"))
g_nyc2 <- filter_feed_by_area(g_nyc, c(-74.0144, 40.7402, -73.9581, 40.7696))

x1 = cluster_stops(g_nyc2$stops)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-travel_times.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ test_that("feed without transfers", {

test_that("nyc feed", {
skip_on_cran()
nyc_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
nyc_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
nyc <- read_gtfs(nyc_path)

.child_index = which(nyc$stops$location_type == 0)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test_that("filter_feed with shapes", {

test_that("filter_feed_by_date", {
skip_on_cran()
g0 = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip",
g0 = read_gtfs(system.file("extdata", "nyc_subway.zip",
package = "tidytransit"))
g1 = filter_feed_by_date(g0, "2018-06-28")
g2 = filter_feed_by_date(g0, "2018-10-30")
Expand Down
21 changes: 11 additions & 10 deletions vignettes/frequency.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ options(dplyr.summarise.inform=F)
## Introduction

The focus of this vignette is on how to use R to make graphics about where and how often
transit service operates based on schedule data published in the [General Transit Feed Specification](https://gtfs.org/).
transit services operate based on schedule data published in the [General Transit Feed Specification](https://gtfs.org/).
We'll focus on the New York City Metropolitan Transit Agency's Subway schedule for this
vignette, but you can easily apply it to thousands of other GTFS data sources. See the
[tidytransit introductory vignette](https://r-transit.github.io/tidytransit/articles/introduction.html#finding-more-gtfs-feeds)
Expand All @@ -50,12 +50,13 @@ We'll start by importing a snapshot of the NYC MTA's subway schedule, which is i
with the package when [installed](https://r-transit.github.io/tidytransit/index.html#installation).

```{r}
local_gtfs_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
local_gtfs_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
gtfs <- read_gtfs(local_gtfs_path)
```

But note that you can also just uncomment the line below and import the data from the NYC
MTA's URL directly.
MTA's URL directly. Note that some routes and services have been removed from the exmaple feed
to reduce package size.

```{r}
# gtfs <- read_gtfs("http://web.mta.info/developers/data/nyct/subway/google_transit.zip")
Expand All @@ -65,10 +66,10 @@ MTA's URL directly.

GTFS feeds typically contain a schedule of all the schedules of service for a given system.
Selecting a schedule of service in NYC allows us to focus on, for example, non-holiday
weekday service, in the Fall of 2019. In some feeds, service selection can be more or less
weekday service, in the Fall of 2018. In some feeds, service selection can be more or less
complicated than NYC. In any case, you'll want to read the [service patterns](https://r-transit.github.io/tidytransit/articles/servicepatterns.html)
vignette included in this package in order to see how you can select the right service for
your needs.
your needs.

We use one of the functions described in that vignette to create a table on the gtfs feed
that lets us filter by weekday/weekend service.
Expand Down Expand Up @@ -171,7 +172,7 @@ system on weekdays.

```{r}
am_stop_freq <- get_stop_frequency(gtfs, start_time = 6*3600, end_time = 10*3600,
service_ids = service_ids, by_route = TRUE)
service_ids = service_ids, by_route = TRUE)
```

```{r}
Expand All @@ -196,7 +197,7 @@ stop_name.

```{r}
one_line_stops <- am_stop_freq %>%
filter(route_id == 1 & direction_id == 0) %>%
filter(route_id == "1" & direction_id == 0) %>%
left_join(gtfs$stops, by ="stop_id") %>%
mutate(mean_headway_minutes = mean_headway/60)
```
Expand Down Expand Up @@ -295,7 +296,7 @@ routes_sf <- routes_sf %>%

And finally, lets plot the routes with median headways of less than 10 minutes in the morning.

```{r, fig.width=6, fig.height=10, warn=FALSE}
```{r, fig.width=6, fig.height=8, warn=FALSE}
# convert to an appropriate coordinate reference system
routes_sf_crs <- sf::st_transform(routes_sf, 26919)
routes_sf_crs %>%
Expand Down Expand Up @@ -337,7 +338,7 @@ routes_sf_buffer <- st_buffer(routes_sf,
Next, when we render the map, we'll make sure to make the borders around each route
transparent, and set the opacity for the fill of all the polygons high again.

```{r, fig.width=6, fig.height=10}
```{r, fig.width=6, fig.height=7}
routes_sf_buffer %>%
ggplot() +
geom_sf(colour = alpha("white", 0), fill = alpha("red",0.2)) +
Expand Down Expand Up @@ -378,7 +379,7 @@ am_stop_name_departures <- am_stop_name_departures %>%

Finally, we can plot both the route line counts and the stop departure counts on one map:

```{r, fig.width=6, fig.height=10}
```{r, fig.width=6, fig.height=7}
ggplot() +
geom_sf(data = routes_sf_buffer,
colour = alpha("white",0), fill = alpha("red",0.3)) +
Expand Down
11 changes: 5 additions & 6 deletions vignettes/introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ a list of the tables in each feed.
Below we use the tidytransit `read_gtfs` function in order to read a feed from the NYC MTA
into R.

We use a feed included in the package in the example below. But note that you can read
We use an example feed included in the package in the example below. But note that you can read
directly from the New York City Metropolitan Transit Authority, as shown in the commented
code below.
code below.

You can also read from any other URL. This is useful because there are many sources for
GTFS data, and often the best source is transit service providers themselves. See the next
Expand All @@ -74,7 +74,7 @@ section on "Finding More GTFS Feeds" for more sources of feeds.
# nyc <- read_gtfs("http://web.mta.info/developers/data/nyct/subway/google_transit.zip")
local_gtfs_path <- system.file("extdata",
"google_transit_nyc_subway.zip",
"nyc_subway.zip",
package = "tidytransit")
nyc <- read_gtfs(local_gtfs_path)
```
Expand Down Expand Up @@ -187,14 +187,13 @@ MobilityData_sf = MobilityData_feedlist %>%
ungroup() %>% st_as_sf()
```

Now show the feeds on a map:
These boxes could now be shown on an interactive map.

```{r, fig.width=7}
```{r, fig.width=7, eval=FALSE}
library(leaflet)
leaflet() %>%
addProviderTiles(provider = providers$CartoDB.Positron) %>%
addPolygons(data = MobilityData_sf, weight = 2,
fillOpacity = 0.1, label = substr(MobilityData_sf$provider, 0, 60))
```

Loading

0 comments on commit af395fb

Please sign in to comment.