These functions are equivalent to write_csv() etc., but instead of writing to disk, they return a string.

format_delim(x, delim, 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)

Arguments

x

A data frame to write to disk

delim

Delimiter used to separate values. Defaults to " " for write_delim(), "," for write_excel_csv() and ";" for write_excel_csv2(). Must be a single character.

na

String used for missing values. Defaults to NA. Missing values will never be quoted; strings with the same value as na will always be quoted.

append

If FALSE, will overwrite existing file. If TRUE, will append to existing file. In both cases, if file does not exist a new file is created.

col_names

Write columns names at the top of the file? Must be either TRUE or FALSE.

Value

A string.

Output

Factors are coerced to character. Doubles are formatted using the grisu3 algorithm. POSIXct's are formatted as ISO8601 with a UTC timezone Note: POSIXctobjects in local or non-UTC timezones will be converted to UTC time before writing.

All columns are encoded as UTF-8. write_excel_csv() and write_excel_csv2() also include a UTF-8 Byte order mark which indicates to Excel the csv is UTF-8 encoded. write_excel_csv2() was created to allow users with different locale settings save csv files with their default settings ; as column separator and , as decimal separator.

Values are only quoted if needed: if they contain a comma, quote or newline.

References

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