Skip to content

fwrite ignores dateTimeAs for datetime sequences #3535

@alistaire47

Description

@alistaire47

If a datetime is generated by seq, fwrite writes it as an epoch timestamp, ignoring the default dateTimeAs = "ISO", likely because of an ALTREP issue. Explicitly setting dateTimeAs to "ISO" makes no difference.

Reprex:

library(data.table)
Sys.setenv(TZ = 'UTC')
tmp <- tempfile()

# epoch instead of ISO
dt <- data.table(x = seq(as.POSIXct('1970-01-01'), by = '1 sec', length = 6))
fwrite(dt, tmp)
cat(readLines(tmp), sep = '\n')
#> x
#> 0
#> 1
#> 2
#> 3
#> 4
#> 5

# works correctly
dt[, x := x + 1]
fwrite(dt, tmp)
cat(readLines(tmp), sep = '\n')
#> x
#> 1970-01-01T00:00:01Z
#> 1970-01-01T00:00:02Z
#> 1970-01-01T00:00:03Z
#> 1970-01-01T00:00:04Z
#> 1970-01-01T00:00:05Z
#> 1970-01-01T00:00:06Z
Session info
> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.4

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.5.2   prettycode_1.0.2 parallel_3.5.2   withr_2.1.2
[5] crayon_1.3.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions