Skip to contents

Add YAML header info and writes a the data.frame into disk. The YAML section includes notes and str(dt).

Usage

obs_write_csvy(
  dt,
  notes,
  out = paste0(tempfile(), ".csvy"),
  sep = ",",
  nchar.max = 80,
  ...
)

Arguments

dt

data.table

notes

notes.

out

outfile path.

sep

The separator between columns. Default is ",".

nchar.max

Max nchar for str.

...

extra data.table arguments

Examples

{
df <- data.frame(a = rnorm(n = 10),
                 time = Sys.time() + 1:10)

f <- paste0(tempfile(), ".csvy")
notes <- c("notes",
           "more notes")
obs_write_csvy(dt = df, notes = notes, out = f)
readLines(f)
data.table::fread(f, h = TRUE)
}
#>               a                time
#>           <num>              <POSc>
#>  1: -0.55369938 2024-11-14 00:28:30
#>  2:  0.62898204 2024-11-14 00:28:31
#>  3:  2.06502490 2024-11-14 00:28:32
#>  4: -1.63098940 2024-11-14 00:28:33
#>  5:  0.51242695 2024-11-14 00:28:34
#>  6: -1.86301149 2024-11-14 00:28:35
#>  7: -0.52201251 2024-11-14 00:28:36
#>  8: -0.05260191 2024-11-14 00:28:37
#>  9:  0.54299634 2024-11-14 00:28:38
#> 10: -0.91407483 2024-11-14 00:28:39