View source: R/Data_handling.R
write_eddy | R Documentation |
Facilitates printing object x
also with its units of measurement (or
space efficient metadata) to a file or connection
.
write_eddy(
x,
file = "",
append = FALSE,
quote = TRUE,
sep = ",",
units_fill = "-",
na = "-9999",
row.names = FALSE,
col.names = TRUE,
qmethod = "double",
...
)
x |
The object that will be written. It is a data frame with optional
attributes |
file |
Either a character string naming a file to write to or a
|
append |
A logical value. It is considered only if |
quote |
A logical value ( |
sep |
A character used as the field separator of each row. |
units_fill |
A character string that represents missing value of
|
na |
A character string that represents missing data values in the output. |
row.names |
Either a logical value ( |
col.names |
Either a logical value ( |
qmethod |
A character string. It determines the way how strings quoting
is performed in case of embedded double quote characters. The options are
either |
... |
Further arguments to be passed to the internal
|
write_eddy
extends the possibilities of write.table
so the
units of measurement can also be written. However, it uses default arguments
of write.csv
to provide flexibility for the user and to accomodate the
function for the most common case. The character string "-9999"
is
typically used to represent missing values in eddy covariance (eddy)
data.
Storing varnames
and units
attributes is practical mostly
within data frames and vectors. Attribute varnames
extracted from each
data frame column represents names of respective variables and its main
purpose is to keep variable names of isolated vectors. Attribute units
extracted from each column represents units of measurement (or space
efficient metadata) of respective variables that are written one line above
data region. If the varnames
or units
attribute of given column
is NULL
, of length not equal to 1, or contains missing value or empty
string, it is not considered meaningful. In that case the default column name
produced by as.data.frame
is used instead (considered only if
x
is supplied as vector) and unit of measurement is substituted with
units_fill
string. units_fill
can be an empty string.
Units of measurement are considered to be part of the output header and
therefore col.names
and quote
arguments have the effect on the
way they are written.
write.table
for information about full list of allowed
arguments and their descriptions.
read_eddy
to read data frame with varnames
and
units
attributes specified for each column.
xx <- read_eddy(text =
"timestamp,height,weight
%d.%m.%Y,m,kg
24.1.2015,1.70,75
24.1.2016,1.72,78")
str(xx)
write_eddy(xx, "")
## NB: 'varnames' and 'units' attributes are dropped when you subset rows
## but unchanged if you subset columns:
write_eddy(xx[, 1], "") # 'varnames' attribute of the vector used as column name
write_eddy(head(xx), "") # dropped 'units' attribute
## Not run:
# Example of using "col.names = NA"
zz <- file("ex.data", "w") # open an output file connection
write_eddy(xx, zz, row.names = T, col.names = NA)
close(zz)
(ex_data <- read_eddy("ex.data", row.names = 1))
str(ex_data)
unlink("ex.data")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.