write_eddy: Eddy Covariance Data Output

View source: R/Data_handling.R

write_eddyR Documentation

Eddy Covariance Data Output

Description

Facilitates printing object x also with its units of measurement (or space efficient metadata) to a file or connection.

Usage

write_eddy(
  x,
  file = "",
  append = FALSE,
  quote = TRUE,
  sep = ",",
  units_fill = "-",
  na = "-9999",
  row.names = FALSE,
  col.names = TRUE,
  qmethod = "double",
  ...
)

Arguments

x

The object that will be written. It is a data frame with optional attributes units and varnames assigned to each column. Otherwise it is converted by as.data.frame.

file

Either a character string naming a file to write to or a connection that is open for writing. "" results in writing to the console.

append

A logical value. It is considered only if file is not a connection. If TRUE, the output is written below the content of the file. If FALSE, the content of the file is overwritten.

quote

A logical value (TRUE or FALSE) or a numeric vector. If TRUE, columns of class character or factor will be surrounded by double quotes. If a numeric vector, its elements should mark the indices of character or factor columns to quote. In both cases, row and column names and units are quoted if present. If FALSE, no quoting is performed.

sep

A character used as the field separator of each row.

units_fill

A character string that represents missing value of units attribute in the output.

na

A character string that represents missing data values in the output.

row.names

Either a logical value (TRUE or FALSE) that determines if the row names of x should be included in the output, or a character vector of row names that will be used instead.

col.names

Either a logical value (TRUE, FALSE or NA) or a character vector. If TRUE, column names of x will be included in the output. If a character vector, its elements will be used as column names. If x is supplied as vector, an attempt is made to extract meaningful variable name from its attribute varnames. In all cases, units extracted from units attribute of each column will be written one line below column names with identical format. See the 'CSV files' section in write.table for further explanation of col.names = NA.

qmethod

A character string. It determines the way how strings quoting is performed in case of embedded double quote characters. The options are either "double" (write.csv and write.csv2 defaults), that doubles the quote character, or "escape" (write.table default), that escapes it in C style by a backslash.

...

Further arguments to be passed to the internal write.table function.

Details

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.

See Also

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.

Examples

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)


lsigut/openeddy documentation built on Aug. 5, 2023, 12:25 a.m.