Skip to content

Commit

Permalink
gtfs objects now explicitly inherit from lists as well. thanks @mpadge
Browse files Browse the repository at this point in the history
  • Loading branch information
dhersz committed Jun 17, 2021
1 parent 1ed0e63 commit 322576d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: gtfsio
Title: Read and Write General Transit Feed Specification (GTFS) Files
Version: 0.1.2.9000
Version: 0.1.2.9001
Authors@R:
c(person(given = "Daniel",
family = "Herszenhut",
Expand Down
2 changes: 1 addition & 1 deletion R/gtfs_subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# make sure that the resulting object keeps the original object classes

subclass <- setdiff(class(x), "gtfs")
subclass <- setdiff(class(x), c("gtfs", "list"))

return(new_gtfs(NextMethod(), subclass = subclass))

Expand Down
8 changes: 4 additions & 4 deletions R/new_gtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' @param ... Name-value pairs. Additional attributes.
#'
#' @return A GTFS object: a named list of data frames, each one corresponding to
#' a distinct GTFS text file, with \code{gtfs} class.
#' a distinct GTFS text file, with \code{gtfs} and \code{list} classes.
#'
#' @family constructors
#'
Expand Down Expand Up @@ -58,10 +58,10 @@ new_gtfs <- function(x, subclass = character(), ...) {

if (!is.character(subclass)) stop("'subclass' must be a character vector.")

# append "gtfs" to 'subclass', so any objects created by 'new_gtfs()' always
# inherit from gtfs class
# append "gtfs" and "list" to 'subclass', so any objects created by
# 'new_gtfs()' always inherit from gtfs and list classes

class <- c(subclass, "gtfs")
class <- c(subclass, "gtfs", "list")

# create object

Expand Down
4 changes: 2 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"codeRepository": "https://github.com/r-transit/gtfsio",
"issueTracker": "https://github.com/r-transit/gtfsio/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.1.2.9000",
"version": "0.1.2.9001",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down Expand Up @@ -123,7 +123,7 @@
"sameAs": "https://CRAN.R-project.org/package=zip"
}
],
"fileSize": "17784.06KB",
"fileSize": "151531.429KB",
"keywords": [
"r",
"gtfs"
Expand Down
11 changes: 6 additions & 5 deletions inst/tinytest/test_new_gtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ expect_error(

no_class_gtfs <- unclass(gtfs)

# by default an object created with new_gtfs() should inherent from 'gtfs' only
# by default an object created with new_gtfs() should inherent from 'gtfs' and
# 'list' only

default <- new_gtfs(no_class_gtfs)

expect_identical(class(default), "gtfs")
expect_identical(class(default), c("gtfs", "list"))

# if a subclass is specified, the object should inherit both from 'gtfs' and the
# subclass
# if a subclass is specified, the object should inherit from 'gtfs', 'list' and
# the subclass

extra_class <- new_gtfs(no_class_gtfs, subclass = "subclass")

expect_identical(class(extra_class), c("subclass", "gtfs"))
expect_identical(class(extra_class), c("subclass", "gtfs", "list"))

# attributes passed to '...' should be assigned to the object

Expand Down
2 changes: 1 addition & 1 deletion man/new_gtfs.Rd

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

1 comment on commit 322576d

@mpadge
Copy link
Collaborator

@mpadge mpadge commented on 322576d Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

Please sign in to comment.