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.25148344 2025-07-24 19:17:37
#>  2:  0.44479712 2025-07-24 19:17:38
#>  3:  2.75541758 2025-07-24 19:17:39
#>  4:  0.04653138 2025-07-24 19:17:40
#>  5:  0.57770907 2025-07-24 19:17:41
#>  6:  0.11819487 2025-07-24 19:17:42
#>  7: -1.91172049 2025-07-24 19:17:43
#>  8:  0.86208648 2025-07-24 19:17:44
#>  9: -0.24323674 2025-07-24 19:17:45
#> 10: -0.20608719 2025-07-24 19:17:46