yywrite: Easily write files

yywriteR Documentation

Easily write files

Description

Function from data.table.

Usage

yywrite(
  x,
  file = "",
  rownames.id,
  col.names = TRUE,
  method = c("vroom", "write"),
  sep,
  eol = c("\n", "\r\n", "\r"),
  ...
)

Arguments

x

Any list of same length vectors; e.g. data.frame and data.table. If matrix, it gets internally coerced to data.table preserving col names but not row names

file

Output file name. "" indicates output to the console.

rownames.id

A string: the name of a new column. Existing rownames are transferred into this column and the row.names attribute is deleted.

col.names

Should the column names (header row) be written? The default is TRUE for new files and when overwriting existing files (append=FALSE). Otherwise, the default is FALSE to prevent column names appearing again mid-file when stacking a set of data.tables or appending rows to the end of a file.

method

c("vroom", "fwrite"). The function used to write file, the default is "vroom".

sep

The separator between columns. Default "," for "csv" file; "\t" otherswise.

eol

Default "\n", you can also use "\r\n" and "\r".

...

others params from vroom::vroom_write() or data.table::fwrite(). Just like "num_threads" in vroom; "nThread" in data.table.

Examples

## Not run: 
a1 <- data.frame(matrix(1:9, 3))
yywrite(a1, "a1.tsv")
yywrite(a1, "a1.csv")
rownames(a1) <- letters[1:3]
yywrite(a1, "a1_name.tsv", row.names = TRUE)
yywrite(a1, "a1_name_no_colname.tsv", row.names = TRUE, col.names = FALSE)

## End(Not run)

yanpd01/yyeasy documentation built on Dec. 1, 2022, 10:58 p.m.