Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions R/fwrite.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@
x
})
}

Check warning on line 124 in R/fwrite.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/fwrite.R,line=124,col=1,[trailing_whitespace_linter] Remove trailing whitespace.
# ensure POSIXct columns are double for proper ISO formatting
x <- lapply(x, function(col) {
if (inherits(col, "POSIXt")) {
# coerce integer-backed to double
storage.mode(col) <- "double"
}
col
})

Check warning on line 133 in R/fwrite.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/fwrite.R,line=133,col=1,[trailing_whitespace_linter] Remove trailing whitespace.
.Call(CfwriteR, x, file, sep, sep2, eol, na, dec, quote, qmethod=="escape", append,
row.names, col.names, logical01, scipen, dateTimeAs, buffMB, nThread,
showProgress, is_gzip, compressLevel, bom, yaml, verbose, encoding, forceDecimal)
Expand Down
30 changes: 30 additions & 0 deletions inst/tests/fwrite-datetime.Rraw.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
test(
"fwrite: POSIXct should be written as ISO-8601, not numeric seconds",
{
oldtz = Sys.getenv("TZ", unset = NA)
on.exit({
if (is.na(oldtz)) Sys.unsetenv("TZ") else Sys.setenv(TZ = oldtz)
}, add = TRUE)

Sys.setenv(TZ = "UTC")

DT = data.table(
x = seq(
as.POSIXct("1970-01-01", tz = "UTC"),
by = "1 sec",
length.out = 3
)
)

tmp = tempfile()
fwrite(DT, tmp)

out = readLines(tmp)

stopifnot(
out[1L] == "x",
out[2L] == "1970-01-01T00:00:00Z",
out[3L] == "1970-01-01T00:00:01Z",
out[4L] == "1970-01-01T00:00:02Z"
)
})
1 change: 1 addition & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -21509,3 +21509,4 @@ setdroplevels(x)
setdroplevels(y)
test(2364.2, levels(x$a), levels(y$a))
rm(x, y)

Loading