Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

export

Export a dataframe to a file or a connection


Description

This function is a wrapper to write.table(), to overcome possible issues with the row names.

Usage

export(x, file = "", ...)

Arguments

x

The object to be written (matrix or dataframe)

file

A character string containing the path to the file to be created

...

Same arguments that are used in write.table()

Details

The default convention for write.table() is to add a blank column name for the row names, but (despite it is a standard used for CSV files) that doesn't work with all spreadsheets or other programs that attempt to import the result of write.table().

This function acts as if write.table() was called, with only one difference: if row names are present in the dataframe (i.e. any of them should be different from the default row numbers), the final result will display a new column called cases in the first position, except the situation that another column called cases already exists in the data, when the row names will be completely ignored.

If not otherwise specified, an argument sep = "," is added by default.

The argument row.names is always set to FALSE, a new column being added anyways (if possible).

Since this function pipes everything to write.table(), the argument file can also be a connection open for writing, and "" indicates output to the console.

Author(s)

Adrian Dusa

See Also

The “R Data Import/Export” manual.


admisc

Adrian Dusa's Miscellaneous

v0.12
GPL (>= 3)
Authors
Adrian Dusa [aut, cre, cph] (<https://orcid.org/0000-0002-3525-9253>)
Initial release
2021-03-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.