| write.sheet | R Documentation |
Write a ring width object to a file in “spreadsheet” layout: years down the rows, series across the columns, and the years in the first column.
write.sheet(rwl.df, fname, sep = ",", dec = ".",
layout = c("wide", "long"), prec = NULL, na.string = "",
year.name = "Year")
rwl.df |
a |
fname |
a |
sep |
the field separator, a single character. |
dec |
the decimal mark, |
layout |
the shape to write. |
prec |
the precision to write, in mm, or |
na.string |
|
year.name |
|
The file is written in the layout that read.sheet reads: a
header row of the year column's name followed by the series IDs,
then one row per year.
prec controls how many decimal places are written. Left at
NULL it is taken from the "dplR.provenance" attribute that
read.sheet and read.tucson attach to the objects
they return, and failing that it is inferred from the data. This is what
keeps a width read at 0.001 mm from being written back as
0.5670000000000001.
A precision that was derived rather than given is checked against the data
before it is used, and if rounding there would discard real digits the file
is written at full precision with a warning instead. A precision passed
explicitly is an instruction and is obeyed, so prec = 0.1 rounds.
Trailing zeros are kept: at prec = 0.001 a width of 0.51 is
written as 0.510.
With layout = "long" the file holds one row per observation — the
series ID, the year and the value — with missing values left
out. Rows are written one series at a time, years ascending within a
series. year.name names the year column here too.
A year in which every series is NA has no rows. An
interior such year still survives a round trip, because
read.sheet rebuilds the span from the earliest and latest
year in the file and the year reappears as a row of NA in its
original place. A leading or trailing one has nothing outside it
to pin the span and is lost; write.sheet warns when it writes a
file in that state. Write with layout = "wide" to keep those years.
A ring width of zero is a locally absent ring and is written as a zero. A
missing value is written as na.string. The two are different statements
about a tree in a year and are never written the same way.
Series IDs are written verbatim. An ID containing the separator, a double quote or a line break is quoted using the usual comma-separated-value escape.
The function returns fname, the name of the file written.
Andy Bunn
read.sheet, write.rwl,
write.tucson
library(utils)
data(ca533)
tmpName <- tempfile(fileext = ".csv")
# write and read back
write.sheet(ca533, tmpName)
bar <- read.sheet(tmpName, verbose = FALSE)
# the data survives the round trip unchanged. Provenance describes the file an
# object was read from, so it is dropped from both sides before comparing.
no.prov <- function(x) { attr(x, "dplR.provenance") <- NULL; x }
identical(no.prov(ca533), no.prov(bar))
unlink(tmpName)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.