From 4b194e86fced6a1c0ef5304a2ad4c9634c9e6cba Mon Sep 17 00:00:00 2001 From: meggehsc Date: Sat, 25 May 2024 10:42:24 -0600 Subject: [PATCH] various fixes to appease CRAN --- .Rbuildignore | 41 ++++++++++++++++++ .gitignore | 1 + DESCRIPTION | 10 ++--- R/data.R | 13 ++++++ R/functions.R | 35 ++++++++++++++- R/sysdata.rda | Bin 1334 -> 0 bytes R/tpm.R | 1 - README.md | 4 +- data/fips_lookup.rda | Bin 0 -> 1278 bytes man/{ => figures}/mdd_1.png | Bin man/{ => figures}/mdd_2.png | Bin man/{ => figures}/phed_data_reqs.png | Bin man/fips_lookup.Rd | 23 ++++++++++ man/tpm.Rd | 14 ------ tests/testthat/test-hpms.R | 12 ++--- tests/testthat/test-lottr.R | 2 +- tests/testthat/test-phed.R | 33 +++++++------- tests/testthat/test-tttr.R | 2 +- tests/testthat/{ => testdata}/Readings.csv | 0 .../TMC_Identification.csv} | 6 +-- .../testthat/{ => testdata}/speed_limits.csv | 2 +- 21 files changed, 148 insertions(+), 51 deletions(-) create mode 100644 R/data.R delete mode 100644 R/sysdata.rda create mode 100644 data/fips_lookup.rda rename man/{ => figures}/mdd_1.png (100%) rename man/{ => figures}/mdd_2.png (100%) rename man/{ => figures}/phed_data_reqs.png (100%) create mode 100644 man/fips_lookup.Rd rename tests/testthat/{ => testdata}/Readings.csv (100%) rename tests/testthat/{tmc_identification.csv => testdata/TMC_Identification.csv} (83%) rename tests/testthat/{ => testdata}/speed_limits.csv (91%) diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..f2fa183 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,43 @@ +^pkgdown$ ^.*\.Rproj$ ^\.Rproj\.user$ +^\.travis\.yml$ +^.Rprofile$ +^inst/db$ +^inst/bench$ +^man-roxygen$ +^demo/pandas$ +^\.httr-oauth$ +^cran-comments\.md$ +^README\.Rmd$ +^revdep$ +^README-.*\.png$ +^codecov\.yml$ +^appveyor\.yml$ +^Doxyfile$ +^clion-test\.R$ +^API$ +^ISSUE_TEMPLATE\.md$ +^data-raw$ +^LICENSE\.md$ +^BROWSE$ +^GPATH$ +^GRTAGS$ +^GTAGS$ +^TAGS$ +^\.dir-locals\.el$ +^vignettes/rsconnect$ +^docs$ +^_pkgdown\.yml$ +^issues$ +^CONDUCT\.md$ +^archive$ +^\.drake$ +^CRAN-RELEASE$ +^\.github$ +^\.github/workflows/R-CMD-check\.yaml$ +^\.github/workflows/pr-commands\.yaml$ +^\.github/workflows/pkgdown\.yaml$ +^doc$ +^Meta$ +^CRAN-SUBMISSION$ diff --git a/.gitignore b/.gitignore index de81a08..1830b26 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .Rhistory .RData .Ruserdata +tpm.Rcheck/ test_data/* \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 9adf92d..eb2ef28 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,18 +1,18 @@ Package: tpm Title: FHWA TPM Score Calculation Functions -Version: 1.2.0 +Version: 2.0.1 Authors@R: person(given = "Mark", family = "Egge", role = c("aut", "cre"), - email = "egge@highstreetconsulting.com", - comment = c(ORCID = "YOUR-ORCID-ID")) -Description: Contains functions for calculating TPM PM3 Level of Travel Time Reliability and Truck Travel Time Reliability metric scores from NPMRDS travel time data and for calculating statewide reliability performance measures. + email = "mark@eateggs.com", + comment = c(ORCID = "0009-0007-9128-2099")) +Description: Contains functions for calculating the Federal Highway Administration (FHWA) Transportation Performance Management (TPM) performance measures. Currently, the package provides methods for the System Reliablity and Freight (PM3) performance measures calculated from travel time data provided by The National Performance Management Research Data Set (NPMRDS), including Level of Travel Time Reliability (LOTTR), Truck Travel Time Reliability (TTTR), and Peak Hour Excessive Delay (PHED) metric scores for calculating statewide reliability performance measures. License: Mozilla Public License Version 2.0 Encoding: UTF-8 URL: https://github.com/markegge/fhwa_pm3/ BugReports: https://github.com/markegge/fhwa_pm3/issues -LazyData: false +LazyData: true Depends: R (>= 3.5.0) Imports: diff --git a/R/data.R b/R/data.R new file mode 100644 index 0000000..8f8c32e --- /dev/null +++ b/R/data.R @@ -0,0 +1,13 @@ +#' FIPS Codes +#' +#' This dataset provides a crosswalk between state names, postal codes, and +#' FIPS codes. Used by the hpms() function. The variables are as follows: +#' +#' @format A data frame with 56rows and 4 variables: +#' \describe{ +#' \item{State_Name}{state name (e.g. 'Alabama')} +#' \item{Postal_Code}{two character state postal code (e.g. 'AL')} +#' \item{FIPS_Code}{Census Bureau FIPS Code (e.g. 1)} +#' \item{STATE_NAME}{capitalized state name (e.g. 'ALAMABA')} +#' } +"fips_lookup" \ No newline at end of file diff --git a/R/functions.R b/R/functions.R index 6851c50..a722e62 100644 --- a/R/functions.R +++ b/R/functions.R @@ -1,3 +1,5 @@ +utils::globalVariables(".") +utils::globalVariables(c("errorMessage")) #' Calculate LOTTR Metric Score #' #' Calculate LOTTR given a RITIS NPMRDS export of travel time data. @@ -19,6 +21,10 @@ #' #' @export lottr <- function(travel_time_readings = NULL, monthly = FALSE, verbose = FALSE) { + # bind variables to an object to suppress R CMD check warnings + max_lottr <- score_weekday_am <- score_weekday_mid <- score_weekday_pm <- score_weekend <- NULL + weekday_am <- weekday_mid <- weekday_pm <- weekend <- reliable <- NULL + scores <- score(travel_time_readings, metric = "LOTTR", monthly, verbose) if(verbose == TRUE) { @@ -53,6 +59,10 @@ lottr <- function(travel_time_readings = NULL, monthly = FALSE, verbose = FALSE) #' #' @export tttr <- function(travel_time_readings = NULL, monthly = FALSE, verbose = FALSE) { + # bind variables to an object to suppress R CMD check warnings + max_tttr <- score_weekday_am <- score_weekday_mid <- score_weekday_pm <- score_overnight <- score_weekend <- NULL + weekday_am <- weekday_mid <- weekday_pm <- weekend <- overnight <- NULL + scores <- score(travel_time_readings, metric = "TTTR", monthly, verbose) if(verbose == TRUE) { @@ -92,6 +102,10 @@ tttr <- function(travel_time_readings = NULL, monthly = FALSE, verbose = FALSE) #' } score <- function(input_file = NULL, metric, monthly = FALSE, verbose = FALSE) { + # bind variables to an object to suppress R CMD check warnings + measurement_tstamp <- period <- dow <- nhpp_period <- hod <- travel_time_seconds <- NULL + numerator <- denominator <- NULL + if (!is.null(input_file)) { DT <- fread(input_file) } else { @@ -269,6 +283,11 @@ phed <- function(travel_time_readings, tmc_identification, dow_factor = dow_factor_default, hod_profile = hod_profile_default, population = NA) { + # bind variables to an object to suppress R CMD check warnings + day <- faciltype <- nhs <- road_class <- f_system <- aadt_cars <- aadt <- NULL + aadt_singl <- aadt_combi <- aadp <- nhs_pct <- hod_factor <- speed_limit <- NULL + threshold_speed <- threshold_travel_time <- miles <- measurement_tstamp <- NULL + tmc <- delay_seconds <- travel_time_seconds <- delay_person_hours <- delay <- NULL if(as.integer(pm_peak) == 3) { hours <- c(6, 7, 8, 9, 15, 16, 17, 18) # 3 - 7 pm @@ -380,6 +399,11 @@ phed <- function(travel_time_readings, tmc_identification, } setnames(travel_time, "tmc_code", "tmc") + + missing_tmcs <- tmcs$tmc[!tmcs$tmc %in% travel_time$tmc] + if(length(missing_tmcs) > 0) { + warning(paste("Warning: travel time data missing for ", missing_tmcs, collapse = ",")) + } # join in threshold travel times with TMCs travel_time <- merge(travel_time, tmcs[, .(tmc, road_class, aadp, threshold_travel_time)], by = "tmc") @@ -437,6 +461,15 @@ phed <- function(travel_time_readings, tmc_identification, #' #' @export hpms <- function(tmc_identification, lottr_scores, tttr_scores, phed_scores = NULL, occ_fac = 1.7) { + # bind variables to an object to suppress R CMD check warnings + Postal_Code <- isprimary <- nhs <- tmc <- f_system <- urban_code <- NULL + faciltype <- miles <- nhs_pct <- direction <- aadt <- delay <- PHED <- NULL + tmc_code <- score_weekday_am <- denominator_weekday_am <- numerator_weekday_am <- NULL + score_weekday_mid <- denominator_weekday_mid <- numerator_weekday_mid <- NULL + score_weekday_pm <- denominator_weekday_pm <- numerator_weekday_pm <- NULL + score_weekend <- denominator_weekend <- numerator_weekend <- NULL + score_overnight <- denominator_overnight <- numerator_overnight <- NULL + DT <- fread(tmc_identification) yr <- first(year(DT$active_start_date)) @@ -448,7 +481,7 @@ hpms <- function(tmc_identification, lottr_scores, tttr_scores, phed_scores = NU state <- unique(toupper(DT$state)) stopifnot(length(state) == 1) - state_fips <- tpm:::fips_lookup[Postal_Code == state]$FIPS_Code + state_fips <- tpm::fips_lookup[Postal_Code == state]$FIPS_Code # Set NHS Value appropriately - no zeros allowed by FHWA! DT[isprimary == "0", nhs := -1] diff --git a/R/sysdata.rda b/R/sysdata.rda deleted file mode 100644 index 62d21e4d7e3dbd361e2f1628adcb9a2dde24a18b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1334 zcmV-610$#Ic@c(R7{JAsxL`H!9JE|DY44 zSrSb%$6PuveZ9Isy2dH6MKg4}+9X%_wC)2>6ct{L&eYtl+oa276r0E@ZP0iYDNLkF z%?+~jwo_{MbeyfHi`&9)_02j;x2D#Ziejt1$y9Q?RPn6v51C3+HJz_hon=VLqUk)k zQn96E5!56#nWfxkQJUtz*Vj=wCr!;dv3`S@I4eaoxxPrY_NmVGbA@F(OiZ#U{3C9XZ0@)!F;GoQf3S&m)S^tGD&`Tgh{Y0i zqHHOV=qqEhKN#pZPH&gbRoOKM!Q9NWL({EN9!ax)&Dxvj&f2X|=k-jrO|=&47r3F- zVW#G`iX)w@ppaJRD1vS(Wwgf%Di&X5DE4ry)6BUutTm3(sfp9bj%ti=%?jpOLhlcfAZccQn#A-2Wy>V#tF);IogQ8fxCxzkMz;%q4f-{ zz*;UrOQ026tK*^NTI&>a2(}m;f$U{YhtZFK4rKrLq1kM#nl)xGvs5K z2g5u#^6?Q`K3Y%FVrZc%j+t}RB5I$ss0F?%)R3eK+mJrp4XVw~`=22-O-?+3e zk1?(>M$H7P(H&wn2B;5}j%eP~ulgpxBOp>-2>A_C&rd|&-uX$$n=n6a#rQXie!CBN z8<1Zl4*>51-UGa!H#Oh`z=wd303QQB0elMh4B!Ah2Ydne67Ut^Yrr>vZvo!{z6bmO z_!003a18hf@H5~Sz^{PEfZqVW1O6y-`4eyg@Blu5SMFYNeR4vurRw0y9>IqJeI~ed zn{6DdMVxzDJS z`R`yr%Q;etA)cBB6Fe+MG`V*YZ0%E>dn1BnI^^Ei@d+D9pJJKYdGM(hNN=(oVcr?V z_gyoOOhjN$@(~w7=sPY61XR<~A8eu>(koM_3ZEj2==EVI%9av=*A+JVgMr7nob*Se z?3#nX7ah-`a;ua_kp64d-b8oSZiQZ6PwClIYoT|B8(JNP#J-~%BQMAciI*IOZYpK8 z#{??IyCI4_9D6c!?hI>rq4M%LSB<*YI*L$CxuPs zln&%}pe;iZdgmOHxU)zrF*nC{q5Rdi_c#1``SRsIchyYcL)og?v%E8vspCvtEcH(0 sGRgJr65KzI;tak4)bcph%gaPx7BABr{}%Y4Q{C|X2bW&5LqQAx0IK$vZ~y=R diff --git a/R/tpm.R b/R/tpm.R index 482ce17..f689572 100644 --- a/R/tpm.R +++ b/R/tpm.R @@ -16,7 +16,6 @@ #' \code{\link{hpms}} generates an HPMS submission file in pipe delimited format #' #' -#' @docType package #' @name tpm #' #' @import data.table diff --git a/README.md b/README.md index a637a5a..639b7d3 100644 --- a/README.md +++ b/README.md @@ -80,12 +80,12 @@ To calculate LOTTR or TTTR Metric scores: 3. Choose the appropriate "TMC segments from" value (e.g. "NPMRDS INRIX 2019") 4. Choose your region (e.g. Wyoming) click Add 5. Specify appropriate date range, e.g 01/01/2019 – 12/31/2019 -![Massive Data Downloader Region and Dates](man/mdd_1.png) +![Massive Data Downloader Region and Dates](man/figures/mdd_1.png) 6. Select data sources and measures: * "NPMRDS form INRIX (Trucks and Passenger Vehicles): Travel Time" for LOTTR Measure (the other fields are optional) * "NPMRDS from Inrix (Trucks): Travel Time" for TTTR Measure 9. Set averaging to 15 minutes (per PM3 Final Rule) and Submit -![Massive Data Downloader Data Sources and Units](man/mdd_2.png) +![Massive Data Downloader Data Sources and Units](man/figures/mdd_2.png) 10. Download and extract the resulting dataset 11. Calculate scores using `lottr` and `tttr`. Monthly scores may be calculated using `monthly = TRUE` diff --git a/data/fips_lookup.rda b/data/fips_lookup.rda new file mode 100644 index 0000000000000000000000000000000000000000..3f6d6ff06807172bc8dba85f06ddeadaf8ac4ef0 GIT binary patch literal 1278 zcmVHq|^|HS|Q|NsB@`@}#0-|)Zh-|#>H06+i%&;(wK zk=T~HH&)KHG?A3k38ATzX*AfHO+2F@$QlfcfChsjKmY-tYMN=1Y^EmAm{IBvNCQm( z0000000x1O4O7U_O*9it8URg9)Bpeg00006gVe|X;h-7-4FRAu0009`8fXI`00E;+ zg9%L((1Ln3H8l3A=+x8FWXXsOfO>!c0B8UJ0OZ3FUE82DUY6=bsR3;PaSS!o15}0@ z+F(a81JX^T!4oIIX=dGx9Z8L}n48x-6i+~L*Qh^78kRf|i{6T{ngo8c)}i*TA`l1VI1ozhmVJ@x$Q*7uQ7 zyN7ZysOPD4LC|@WAmNMoMH0$IT@%vzWg(i1JhBp4wwB=f06SU$>9Cf>Z?cfN`y zyGD)OQVXRZkOp%M0Fc1RnSc`shGulmnV1G_iH77R0lnxL-ybZ7wiXQt7Yu7j8CJf{;uaj4Yk7r`68MUeDmYgWx$<*#Abqe09DzbAS6R-(i z+3ZZW2fMSv%7r3Q0Z)fir>me8(YP6fCu~rsLhVNzbW5>q>S3<;oD=Y(gvqVQkSDNi z0ON8-X-Fz!V1UT>eHvo>LM2cY6KN*}n2MEuHaxG(i<@l2Bu+sGD8=2edljVRDOUik z6NrUk-+};O%5Tv_NwFol)>(0v)VyuQJHSgxkcrn1w76qfl=GApgn>=aNRf7!Fn~&PF#M-2zG7A_u@WPoZ_I8wTLMbzpR;|f1W0Jt z=~BZk-cpD`?17u!ZqZH+>)oh&p`k#u%fpa|dv&#!^$Da;ZOUM`7)8MQd|DY24RD-7 zdFKk6X|h$YbmuzJEu%eW8w0~}>4!}O!S73$lCLsPhtOh_(@QYM9113MgUB&B;)a6S zh&V`;R+1%7ZObB9GX`=IwK1yg2LgE|ZLme8xZ`z9YXZWgompr_q=lFpTqbjvF;l8= z^~SjtwGExBMNA?mTs-cw>=_6&GPvX|4vtlVhNO$ND*d_CwXJLcC9qqvyQC#r)~k!h zXsaFd7FjFhSoTR29CI$#*3#wlHuA!ZvUNL&-9m!t8na-hGB4r{98|Mm5`%~@HEgIP zj)3&gDNh1^LMBoHshNfOx%Mnok7o)D#U+GO4x(^!me$!~vmYkL4P%E5C?%ABdgL#9|&sIe+m zw)M{(m+<0a#(BsUmx^q5*w*Y)(Jc&0icA`v7|O0rJ#N<#3i8oVJVQc(MjdD_B3dko z(G)#Gf+UEV%Hu`xCJGQfc1@*;U= oZ82{RSZB$I_9ig-AabF})@9vn9Iy9K5WnK?NT&)C2#bcDK+3~W%>V!Z literal 0 HcmV?d00001 diff --git a/man/mdd_1.png b/man/figures/mdd_1.png similarity index 100% rename from man/mdd_1.png rename to man/figures/mdd_1.png diff --git a/man/mdd_2.png b/man/figures/mdd_2.png similarity index 100% rename from man/mdd_2.png rename to man/figures/mdd_2.png diff --git a/man/phed_data_reqs.png b/man/figures/phed_data_reqs.png similarity index 100% rename from man/phed_data_reqs.png rename to man/figures/phed_data_reqs.png diff --git a/man/fips_lookup.Rd b/man/fips_lookup.Rd new file mode 100644 index 0000000..889976a --- /dev/null +++ b/man/fips_lookup.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{fips_lookup} +\alias{fips_lookup} +\title{FIPS Codes} +\format{ +A data frame with 56rows and 4 variables: +\describe{ + \item{State_Name}{state name (e.g. 'Alabama')} + \item{Postal_Code}{two character state postal code (e.g. 'AL')} + \item{FIPS_Code}{Census Bureau FIPS Code (e.g. 1)} + \item{STATE_NAME}{capitalized state name (e.g. 'ALAMABA')} +} +} +\usage{ +fips_lookup +} +\description{ +This dataset provides a crosswalk between state names, postal codes, and + FIPS codes. Used by the hpms() function. The variables are as follows: +} +\keyword{datasets} diff --git a/man/tpm.Rd b/man/tpm.Rd index 0dc06db..a137971 100644 --- a/man/tpm.Rd +++ b/man/tpm.Rd @@ -1,8 +1,6 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/tpm.R -\docType{package} \name{tpm} -\alias{tpm-package} \alias{tpm} \title{TPM Tools: A package for calculating TPM PM3 Travel Time Reliability Scores from NPMRDS Data} \description{ @@ -24,15 +22,3 @@ The functions \code{\link{hpms}} generates an HPMS submission file in pipe delimited format } -\seealso{ -Useful links: -\itemize{ - \item \url{https://github.com/markegge/fhwa_pm3/} - \item Report bugs at \url{https://github.com/markegge/fhwa_pm3/issues} -} - -} -\author{ -\strong{Maintainer}: Mark Egge \email{egge@highstreetconsulting.com} (\href{https://orcid.org/YOUR-ORCID-ID}{ORCID}) - -} diff --git a/tests/testthat/test-hpms.R b/tests/testthat/test-hpms.R index 4ad2aee..ec0dd37 100644 --- a/tests/testthat/test-hpms.R +++ b/tests/testthat/test-hpms.R @@ -1,13 +1,13 @@ test_that("hpms runs correctly", { expect_equal({ - lottr_scores <- lottr("Readings.csv", verbose = TRUE) - tttr_scores <- tttr("Readings.csv", verbose = TRUE) - phed_scores <- phed(travel_time_readings = "Readings.csv", - tmc_identification = "TMC_Identification.csv", - speed_limits = fread("speed_limits.csv"), + lottr_scores <- lottr(test_path("testdata", "Readings.csv"), verbose = TRUE) + tttr_scores <- tttr(test_path("testdata", "Readings.csv"), verbose = TRUE) + phed_scores <- phed(travel_time_readings = test_path("testdata", "Readings.csv"), + tmc_identification = test_path("testdata", "TMC_Identification.csv"), + speed_limits = fread(test_path("testdata", "speed_limits.csv")), urban_code = 56139, population = 50000) - hpms("TMC_Identification.csv", lottr_scores, tttr_scores, phed_scores) + hpms(test_path("testdata", "TMC_Identification.csv"), lottr_scores, tttr_scores, phed_scores) }, TRUE ) diff --git a/tests/testthat/test-lottr.R b/tests/testthat/test-lottr.R index 192d1fb..623e0fd 100644 --- a/tests/testthat/test-lottr.R +++ b/tests/testthat/test-lottr.R @@ -1,6 +1,6 @@ test_that("null file_path throws error", { expect_warning(score(), ) - scores_monthly <- lottr("Readings.csv", monthly = TRUE) + scores_monthly <- lottr(test_path("testdata", "Readings.csv"), monthly = TRUE) }) \ No newline at end of file diff --git a/tests/testthat/test-phed.R b/tests/testthat/test-phed.R index 62e51f3..3e1a2e0 100644 --- a/tests/testthat/test-phed.R +++ b/tests/testthat/test-phed.R @@ -14,9 +14,9 @@ test_that("phed runs correctly", { 9,0.99,0.99 12,0.97,0.97") - expect_warning(phed(travel_time_readings = "Readings.csv", - tmc_identification = "TMC_Identification.csv", - speed_limits = fread("speed_limits.csv"), + expect_warning(phed(travel_time_readings = test_path("testdata", "Readings.csv"), + tmc_identification = test_path("testdata", "TMC_Identification.csv"), + speed_limits = fread(test_path("testdata", "speed_limits.csv")), urban_code = 56139, population = 52898, moy_factor = moy_factor_test)) @@ -30,9 +30,9 @@ test_that("phed runs correctly", { 4,1.05,1.05 5,1.1,1.1") - expect_warning(phed(travel_time_readings = "Readings.csv", - tmc_identification = "TMC_Identification.csv", - speed_limits = fread("speed_limits.csv"), + expect_warning(phed(travel_time_readings = test_path("testdata", "Readings.csv"), + tmc_identification = test_path("testdata", "TMC_Identification.csv"), + speed_limits = fread(test_path("testdata", "speed_limits.csv")), urban_code = 56139, population = 52898, dow_factor = dow_factor_test)) @@ -46,9 +46,9 @@ test_that("phed runs correctly", { 5,0.05,0.05 6,0.1,0.1") - expect_warning(phed(travel_time_readings = "Readings.csv", - tmc_identification = "TMC_Identification.csv", - speed_limits = fread("speed_limits.csv"), + expect_warning(phed(travel_time_readings = test_path("testdata", "Readings.csv"), + tmc_identification = test_path("testdata", "TMC_Identification.csv"), + speed_limits = fread(test_path("testdata", "speed_limits.csv")), urban_code = 56139, population = 52898, dow_factor = dow_factor_test)) @@ -66,9 +66,9 @@ test_that("phed runs correctly", { 18,0.0555,0.0575 19,0.042,0.047") - expect_warning(phed(travel_time_readings = "Readings.csv", - tmc_identification = "TMC_Identification.csv", - speed_limits = fread("speed_limits.csv"), + expect_warning(phed(travel_time_readings = test_path("testdata", "Readings.csv"), + tmc_identification = test_path("testdata", "TMC_Identification.csv"), + speed_limits = fread(test_path("testdata", "speed_limits.csv")), urban_code = 56139, population = 52898, hod_profile = hod_profile_test)) @@ -76,10 +76,11 @@ test_that("phed runs correctly", { expect_equal({ phed_scores <- phed(urban_code = 56139, population = 52898, - travel_time_readings = "Readings.csv", - tmc_identification = "TMC_Identification.csv", - speed_limits = fread("speed_limits.csv")) - round(phed_scores[, sum(delay) / 52898], 2) + travel_time_readings = test_path("testdata", "Readings.csv"), + tmc_identification = test_path("testdata", "TMC_Identification.csv"), + speed_limits = fread(test_path("testdata", "speed_limits.csv")) + ) + round(phed_scores[, sum(delay, na.rm = TRUE) / 52898], 2) }, 0.18, tolerance = 1 diff --git a/tests/testthat/test-tttr.R b/tests/testthat/test-tttr.R index b051979..9e24f9f 100644 --- a/tests/testthat/test-tttr.R +++ b/tests/testthat/test-tttr.R @@ -5,7 +5,7 @@ test_that("null file_path throws error", { test_that("tttr runs correctly", { expect_equal({ - tttr_scores <- tttr("Readings.csv") + tttr_scores <- tttr(test_path("testdata", "Readings.csv")) mean(tttr_scores$max_tttr) }, 1.638 diff --git a/tests/testthat/Readings.csv b/tests/testthat/testdata/Readings.csv similarity index 100% rename from tests/testthat/Readings.csv rename to tests/testthat/testdata/Readings.csv diff --git a/tests/testthat/tmc_identification.csv b/tests/testthat/testdata/TMC_Identification.csv similarity index 83% rename from tests/testthat/tmc_identification.csv rename to tests/testthat/testdata/TMC_Identification.csv index 2a0e47f..655c159 100644 --- a/tests/testthat/tmc_identification.csv +++ b/tests/testthat/testdata/TMC_Identification.csv @@ -4,8 +4,8 @@ tmc,road,direction,intersection,state,county,zip,start_latitude,start_longitude, 000+10003,US-3,WESTBOUND,,WY,LARAMIE,82009,,,,,0.54,,America/Denver,,USA,,2,N,3,56139,2,,4,3,3,1,3,28730,495,1920,1,100,0,0,1,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z 000P10004,US-4,EASTBOUND,,WY,LARAMIE,82009,,,,,0.08,,America/Denver,,USA,,2,N,3,99999,2,,2,4,4,1,4,2125,45,200,1,100,0,0,1,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z 000-10005,US-5,WESTBOUND,,WY,LARAMIE,82009,,,,,3.45,,America/Denver,,USA,,1,N,1,99999,2,,4,5,5,1,5,28380,425,8050,1,100,0,0,1,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z -000P10006,US-6,WESTBOUND,,WY,LARAMIE,82009,,,,,0.56,,America/Denver,,USA,,2,N,2,56139,2,,6,6,6,1,6,72120,705,1650,1,100,0,0,1,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z -000P10007,US-7,EASTBOUND,,WY,LARAMIE,82009,,,,,1,,America/Denver,,USA,,4,N,3,56139,2,,4,7,7,1,7,18800,325,210,1,100,0,0,0,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z +000P10006,US-6,WESTBOUND,,WY,LARAMIE,82009,,,,,0.56,,America/Denver,,USA,,2,N,2,56139,2,,6,6,6,1,6,12120,405,1250,1,100,0,0,1,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z +000+10007,US-6,WESTBOUND,,WY,LARAMIE,82009,,,,,0.56,,America/Denver,,USA,,2,N,2,56139,2,,6,6,6,1,6,72120,705,1650,1,100,0,0,1,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z 000+10008,US-8,EASTBOUND,,WY,LARAMIE,82009,,,,,1.96,,America/Denver,,USA,,3,N,3,56139,2,,2,8,8,1,8,1670,135,130,1,100,0,0,1,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z -000+10009,US-9,NORTHBOUND,,WY,LARAMIE,82009,,,,,1.83,,America/Denver,,USA,,2,N,3,56139,2,,2,9,9,1,9,1645,35,90,1,100,0,0,1,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z +000P10009,US-10,NORTHBOUND,,WY,LARAMIE,82009,,,,,0.09,,America/Denver,,USA,,2,N,2,99999,2,,4,10,10,1,10,20605,385,4290,1,100,0,0,1,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z 000P10010,US-10,NORTHBOUND,,WY,LARAMIE,82009,,,,,0.09,,America/Denver,,USA,,2,N,2,99999,2,,4,10,10,1,10,30605,585,3290,1,100,0,0,1,1,2020-01-01T05:00:00Z,2021-01-01T05:00:00Z \ No newline at end of file diff --git a/tests/testthat/speed_limits.csv b/tests/testthat/testdata/speed_limits.csv similarity index 91% rename from tests/testthat/speed_limits.csv rename to tests/testthat/testdata/speed_limits.csv index b3b4359..faf2f2f 100644 --- a/tests/testthat/speed_limits.csv +++ b/tests/testthat/testdata/speed_limits.csv @@ -5,7 +5,7 @@ tmc,speed_limit 000P10004,65 000-10005,55 000P10006,55 -000P10007,55 +000+10007,55 000+10008,55 000+10009,45 000P10010,65