save.data.Rd
This function is a wrapper function for saving or writing data frames or matrices.
save.data( data, filename, type="Rdata", path=getwd(), row.names=FALSE, na=NULL,
suffix=NULL, suffix_space="__", index=FALSE, systime=FALSE, ...)
Data frame or matrix to be saved
Name of data file
The type of file in which the data frame or matrix should be loaded.
This can be Rdata
(for R binary format, using
base::save
,
csv
(using utils::write.csv2
),
csv
(using utils::write.csv
),
table
(using utils::write.table
),
sav
(using sjlabelled::write_spss
),
RDS
(using saveRDS
).
type
can also be a vector if the data frame should be
saved in multiple formats.
Directory from which the dataset should be loaded
Optional logical indicating whether row names
should be included in saved csv
or csv2
files.
Missing value handling. The default is ""
for type="csv"
and type="csv2"
and is "."
for type="table"
.
Optional suffix in file name.
Optional place holder if a suffix is used.
Optional logical indicating whether an index should be
included in the first column using the function
index.dataframe
.
If index=TRUE
, this optional logical indicates
whether a time stamp should be included in the second column.
Further arguments to be passed to save
,
write.csv2
, write.csv
, write.table
or sjlabelled::write_spss
.
See load.Rdata
and load.data
for saving/writing R data frames.
if (FALSE) {
#############################################################################
# EXAMPLE 1: Save dataset data.ma01
#############################################################################
#*** use data.ma01 as an example for writing data files using save.data
data(data.ma01)
dat <- data.ma01
# set a working directory
pf2 <- "P:/ARb/temp_miceadds"
# save data in Rdata format
miceadds::save.data( dat, filename="ma01data", type="Rdata", path=pf2)
# save data in table format without row and column names
miceadds::save.data( dat, filename="ma01data", type="table", path=pf2,
row.names=FALSE, na=".", col.names=FALSE)
# save data in csv2 format, including time stamp in file name
# and row index and time stamp in saved data
miceadds::save.data( dat, filename="ma01data", type="csv2", path=pf2,
row.names=FALSE, na="", suffix=systime()[5],
index=TRUE, systime=TRUE )
# save data in sav format
miceadds::save.data( dat, filename="ma02data", type="sav", path=pf2 )
# save data file in different formats
types <- c("Rdata", "csv2", "sav")
sapply( types, FUN=function(type){
miceadds::save.data( dat, filename="ma02data", type=type, path=pf2,
suffix=miceadds::systime()[3], row.names=TRUE )
} )
# save data frame in multiple file formats (sav, table and csv2)
miceadds::save.data( dat, filename="ma03data", type=c("sav","table","csv2"), path=pf2,
suffix=miceadds::systime()[7] )
}