From 69d9499359ade48ba5b2e619ce8fbee8931c7dbe Mon Sep 17 00:00:00 2001 From: gregleleu <33321678+gregleleu@users.noreply.github.com> Date: Thu, 14 Mar 2024 18:52:44 -0400 Subject: [PATCH] Update connection.R - Fix NULL not handled by data.table anymore --- R/connection.R | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/R/connection.R b/R/connection.R index 3acf90e..0035173 100644 --- a/R/connection.R +++ b/R/connection.R @@ -216,24 +216,16 @@ connection <- function(origin, destination, datetime = Sys.time(), rank = rank, section = seq_len(nrow(sec)), departure = sec$departure$time, - origin = vapply( - sec$departure$place$name, - function(x) if (is.na(x)) "ORIG" else x, - character(1) - ), + origin = sec$departure$place$name %||% "ORIG", arrival = sec$arrival$time, - destination = vapply( - sec$arrival$place$name, - function(x) if (is.na(x)) "DEST" else x, - character(1) - ), - mode = sec$transport$mode, - category = sec$transport$category, - vehicle = sec$transport$name, - provider = sec$agency$name, - direction = sec$transport$headsign, - distance = sec$travelSummary$length, - duration = sec$travelSummary$duration, + destination = sec$arrival$place$name %||% "DEST", + mode = sec$transport$mode %||% NA_character_, + category = sec$transport$category %||% NA_character_, + vehicle = sec$transport$name %||% NA_character_, + provider = sec$agency$name %||% NA_character_, + direction = sec$transport$headsign %||% NA_character_, + distance = sec$travelSummary$length %||% NA_real_, + duration = sec$travelSummary$duration %||% NA_real_, geometry = sec$polyline ) }), @@ -278,3 +270,8 @@ connection <- function(origin, destination, datetime = Sys.time(), ), by = list(id, rank)] return(summary) } + + +`%||%` <- function(x, y) { + if (is.null(x)) y else x +}