Skip to content

Commit

Permalink
prevents large round numbers to be saved in scientific notation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhersz committed Oct 19, 2023
1 parent 68808f4 commit c848875
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/export_gtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export_gtfs <- function(gtfs,

# print warning message if warning is raised and 'quiet' is FALSE
withCallingHandlers(
data.table::fwrite(dt, filepath),
data.table::fwrite(dt, filepath, scipen = 999),
warning = function(cnd) {
if (!quiet) message(" - ", conditionMessage(cnd))
}
Expand Down
25 changes: 23 additions & 2 deletions inst/tinytest/test_export_gtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ tester <- function(gtfs_obj = gtfs,
as_dir = FALSE,
overwrite = TRUE,
quiet = TRUE) {

export_gtfs(
gtfs_obj,
path,
Expand All @@ -23,7 +22,6 @@ tester <- function(gtfs_obj = gtfs,
overwrite,
quiet
)

}


Expand Down Expand Up @@ -273,3 +271,26 @@ suppressWarnings(
out <- capture.output(tester(bad_gtfs, quiet = FALSE), type = "message")
)
expect_true(any(grepl("^ - Input has no columns", out)))

# issue #34 ---------------------------------------------------------------

# export_gtfs() should not save large round numbers in scientific notation

mock_shapes <- data.frame(
shape_id = c("a", "b", "c"),
shape_pt_sequence = 1:3,
shape_pt_lat = 40:42,
shape_pt_lon = 40:42,
shape_dist_traveled = c(1, 10000000, 10000001)
)

mock_gtfs <- list(shapes = mock_shapes)
mock_gtfs <- new_gtfs(mock_gtfs)

target_dir <- tempfile()
export_gtfs(mock_gtfs, target_dir, as_dir = TRUE)

resulting_shapes_content <- readLines(file.path(target_dir, "shapes.txt"))

expect_false(identical(resulting_shapes_content[3], "b,2,41,41,1e+07"))
expect_identical(resulting_shapes_content[3], "b,2,41,41,10000000")

0 comments on commit c848875

Please sign in to comment.