write_delim {readr} | R Documentation |
This is about twice as fast as write.csv
, and never
writes row names. output_column
is a generic method used to coerce
columns to suitable output.
write_delim(x, path, delim = " ", na = "NA", append = FALSE, col_names = !append) write_csv(x, path, na = "NA", append = FALSE, col_names = !append) write_excel_csv(x, path, na = "NA", append = FALSE, col_names = !append) write_tsv(x, path, na = "NA", append = FALSE, col_names = !append) format_csv(x, na = "NA", append = FALSE, col_names = !append) format_tsv(x, na = "NA", append = FALSE, col_names = !append) format_delim(x, delim, na = "NA", append = FALSE, col_names = !append) output_column(x)
x |
A data frame to write to disk |
path |
Path to write to. |
delim |
Delimiter used to seperate values. Defaults to |
na |
String used for missing values. Defaults to NA. Missing values
will never be quoted; strings with the same value as |
append |
If |
col_names |
Write columns names at the top of the file? |
write_*
returns the input x
invisibly,
format_*
returns a string.
Factors are coerced to character. Doubles are formatted using the grisu3 algorithm. POSIXct's are formatted as ISO8601.
All columns are encoded as UTF-8. write_excel_csv
also includes a
UTF-8 Byte order mark
which indicates to Excel the csv is UTF-8 encoded.
Values are only quoted if needed: if they contain a comma, quote or newline.
Florian Loitsch, Printing Floating-Point Numbers Quickly and Accurately with Integers, PLDI '10, http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
tmp <- tempfile() write_csv(mtcars, tmp) head(read_csv(tmp)) # format_* is useful for testing and reprexes cat(format_csv(head(mtcars))) cat(format_tsv(head(mtcars))) cat(format_delim(head(mtcars), ";")) df <- data.frame(x = c(1, 2, NA)) format_csv(df, na = ".") # Quotes are automatically as needed df <- data.frame(x = c("a", '"', ",", "\n")) cat(format_csv(df))