Write {lessR} | R Documentation |
Write the Contents of a Data Frame to an External File
Description
Abbreviation: wrt
, wrt_r
, wrt_x
Writes the contents of the specified data frame, such as with the default d
, to the current working directory as either the default csv
data file, an Excel data table, an OpenDocument Spreadsheet file, an arrow feather
or parquet
file, or a native R data file of the specified data frame. If the write is for a csv
file, then any variable labels are written to a second csv
file with "_lbl" appended to the file name. Any variable labels and variable units are automatically included in a native R data file.
Usage
Write(data=d, to=NULL,
format=c("csv", "R", "Excel", "ODS", "SPSS", "feather", "parquet"),
rowNames=NULL,
ExcelTable=FALSE, ExcelColWidth=TRUE,
quiet=getOption("quiet"), ...)
wrt(...)
wrt_r(..., format="R")
wrt_x(..., format="Excel")
Arguments
to |
Name of the output file as a character string, that is, with quotes.
If not included in the name, the file type is automatically added to the
name, either |
data |
Data frame to be written as an object, that is, no quotes. |
format |
Format of file to be written with |
rowNames |
Format of file to be written with |
ExcelTable |
If |
ExcelColWidth |
|
quiet |
If set to |
... |
Other parameter values for |
Details
Can specify the file name without the file type, which Write
adds automatically, .csv
for a comma separated values data file and .rda
for a native R data file. The default file name is the name of the data frame to be written. The name of the file that is written, as well as the name of the working directory into which the file was written, are displayed at the console.
An Excel file is written using functions from Alexander Walker's openxlsx
package.
Write
is designed to work in conjunction with the function Read
from this package, which reads a csv, fixed width format, or native SPSS or R data files into the data frame d
. Write
relies upon the R functions write.csv
and save
.
When writing the data frame in native R format, the specified name of the resulting .rda
file is distinct from the name of the data frame as stored within R.
Author(s)
David W. Gerbing (Portland State University; gerbing@pdx.edu)
See Also
Examples
# create data frame called d
#n <- 12
#X <- sample(c("Group1","Group2"), size=n, replace=TRUE)
#Y <- rnorm(n=n, mean=50, sd=10)
#d <- data.frame(X,Y)
# write the current contents of default data frame d to GoodData.csv
# Write(d, "GoodData")
# short name
# write the default data frame d to the R data file d.rda
# wrt_r()
# write the data as an Excel data table in an Excel file
# Write(d, "GoodData", format="Excel")
# with abbreviation
# wrt_x(d, "GoodData")
# access the R data frame warpbreaks
# then, write the file warpbreaks.rda
# data(warpbreaks)
# wrt_r(warpbreaks)