EVOLUTION-MANAGER
Edit File: write_delim.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Write a data frame to a delimited file</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for write_delim {readr}"><tr><td>write_delim {readr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Write a data frame to a delimited file</h2> <h3>Description</h3> <p>This is about twice as fast as <code><a href="../../utils/html/write.table.html">write.csv()</a></code>, and never writes row names. <code>output_column()</code> is a generic method used to coerce columns to suitable output. </p> <h3>Usage</h3> <pre> write_delim(x, path, delim = " ", na = "NA", append = FALSE, col_names = !append, quote_escape = "double") write_csv(x, path, na = "NA", append = FALSE, col_names = !append, quote_escape = "double") write_csv2(x, path, na = "NA", append = FALSE, col_names = !append, quote_escape = "double") write_excel_csv(x, path, na = "NA", append = FALSE, col_names = !append, delim = ",", quote_escape = "double") write_excel_csv2(x, path, na = "NA", append = FALSE, col_names = !append, delim = ";", quote_escape = "double") write_tsv(x, path, na = "NA", append = FALSE, col_names = !append, quote_escape = "double") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>A data frame to write to disk</p> </td></tr> <tr valign="top"><td><code>path</code></td> <td> <p>Path or connection to write to.</p> </td></tr> <tr valign="top"><td><code>delim</code></td> <td> <p>Delimiter used to separate values. Defaults to <code>" "</code> for <code>write_delim()</code>, <code>","</code> for <code>write_excel_csv()</code> and <code>";"</code> for <code>write_excel_csv2()</code>. Must be a single character.</p> </td></tr> <tr valign="top"><td><code>na</code></td> <td> <p>String used for missing values. Defaults to NA. Missing values will never be quoted; strings with the same value as <code>na</code> will always be quoted.</p> </td></tr> <tr valign="top"><td><code>append</code></td> <td> <p>If <code>FALSE</code>, will overwrite existing file. If <code>TRUE</code>, will append to existing file. In both cases, if file does not exist a new file is created.</p> </td></tr> <tr valign="top"><td><code>col_names</code></td> <td> <p>Write columns names at the top of the file? Must be either <code>TRUE</code> or <code>FALSE</code>.</p> </td></tr> <tr valign="top"><td><code>quote_escape</code></td> <td> <p>The type of escaping to use for quoted values, one of "double", "backslash" or "none". You can also use <code>FALSE</code>, which is equivalent to "none". The default is to double the quotes, which is the format excel expects.</p> </td></tr> </table> <h3>Value</h3> <p><code>write_*()</code> returns the input <code>x</code> invisibly. </p> <h3>Output</h3> <p>Factors are coerced to character. Doubles are formatted using the grisu3 algorithm. POSIXct's are formatted as ISO8601 with a UTC timezone <em>Note: <code>POSIXct</code> objects in local or non-UTC timezones will be converted to UTC time before writing.</em> </p> <p>All columns are encoded as UTF-8. <code>write_excel_csv()</code> and <code>write_excel_csv2()</code> also include a <a href="https://en.wikipedia.org/wiki/Byte_order_mark">UTF-8 Byte order mark</a> which indicates to Excel the csv is UTF-8 encoded. </p> <p><code>write_excel_csv2()</code> and <code>write_csv2</code> were created to allow users with different locale settings save csv files with their default settings <code>;</code> as column separator and <code>,</code> as decimal separator. This is common in some European countries. </p> <p>Values are only quoted if needed: if they contain a comma, quote or newline. </p> <p>The <code>write_*()</code> functions will automatically compress outputs if an appropriate extension is given. At present, three extensions are supported, <code>.gz</code> for gzip compression, <code>.bz2</code> for bzip2 compression and <code>.xz</code> for lzma compression. See the examples for more information. </p> <h3>References</h3> <p>Florian Loitsch, Printing Floating-Point Numbers Quickly and Accurately with Integers, PLDI '10, <a href="http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf">http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf</a> </p> <h3>Examples</h3> <pre> 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)) # A output connection will be automatically created for output filenames # with appropriate extensions. dir <- tempdir() write_tsv(mtcars, file.path(dir, "mtcars.tsv.gz")) write_tsv(mtcars, file.path(dir, "mtcars.tsv.bz2")) write_tsv(mtcars, file.path(dir, "mtcars.tsv.xz")) </pre> <hr /><div style="text-align: center;">[Package <em>readr</em> version 1.3.1 <a href="00Index.html">Index</a>]</div> </body></html>