Skip to content

Commit

Permalink
small optimization to check/assert_field_class()
Browse files Browse the repository at this point in the history
instead of subsetting the data.table and then retrieving the columns'
classes, we now get the classes first and then subset. this change
speeds the function up by a second or so, which is quite noticeable when
we're making function calls in downstream packages (e.g. gtfstools) that
should be quite fast
  • Loading branch information
dhersz committed Mar 21, 2022
1 parent e083a15 commit 984f821
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ check_field_class <- function(x, file, fields, classes) {

# checking - compare the desired classes to the actual classes

actual_classes <- vapply(x[[file]][, ..fields], class, character(1))
col_classes <- vapply(x[[file]], class, character(1))
actual_classes <- col_classes[fields]

if (all(classes == actual_classes)) return(TRUE)

Expand All @@ -227,7 +228,8 @@ assert_field_class <- function(x, file, fields, classes) {

# actual checking - compare the desired classes to the actual classes

actual_classes <- vapply(x[[file]][, ..fields], class, character(1))
col_classes <- vapply(x[[file]], class, character(1))
actual_classes <- col_classes[fields]

if (all(classes == actual_classes)) return(invisible(x))

Expand Down

0 comments on commit 984f821

Please sign in to comment.