Title: | Read and Write StatDataML Files |
---|---|
Description: | Support for reading and writing files in StatDataML---an XML-based data exchange format. |
Authors: | David Meyer [aut, cre] , Torsten Hothorn [aut] , Friedrich Leisch [aut] |
Maintainer: | David Meyer <[email protected]> |
License: | GPL-2 |
Version: | 1.0-27 |
Built: | 2024-12-14 06:26:01 UTC |
Source: | CRAN |
Read a StatDataML file and create a corresponding R object.
readSDML(file="", text=NULL, validate=FALSE, read.description=FALSE, ...)
readSDML(file="", text=NULL, validate=FALSE, read.description=FALSE, ...)
file |
the StatDataML file to be read. |
text |
a string containing StatDataML code (if no file is specified). |
validate |
logical, should |
read.description |
logical, should the |
... |
arguments passed to |
For details on the StatDataML
format see the proposal.
a data object with an additional SDMLdescription
attribute
see also writeSDML
library(XML) TEST <- function(x) identical(readSDML(text = capture.output(writeSDML(x))), x) # write/read vector with names a <- 1:15 names(a) <- paste("n", 1:15, sep="") stopifnot(TEST(a)) # write/read a matrix A <- matrix(1:16, ncol=4) rownames(A) <- paste("row", 1:4, sep="") colnames(A) <- paste("col", 1:4, sep="") stopifnot(TEST(A)) # write/read a data.frame data(iris) stopifnot(TEST(iris)) # write/read a ts object data(airmiles) stopifnot(TEST(airmiles)) # write/read the islands data data(islands) stopifnot(TEST(islands))
library(XML) TEST <- function(x) identical(readSDML(text = capture.output(writeSDML(x))), x) # write/read vector with names a <- 1:15 names(a) <- paste("n", 1:15, sep="") stopifnot(TEST(a)) # write/read a matrix A <- matrix(1:16, ncol=4) rownames(A) <- paste("row", 1:4, sep="") colnames(A) <- paste("col", 1:4, sep="") stopifnot(TEST(A)) # write/read a data.frame data(iris) stopifnot(TEST(iris)) # write/read a ts object data(airmiles) stopifnot(TEST(airmiles)) # write/read the islands data data(islands) stopifnot(TEST(islands))
Write data in StatDataML format, either in a file or to standard output
writeSDML(x, file = "", textdata = NULL, dtd = NULL, sep = " 

", na.string = "NA", null.string = "NULL", posinf.string = "+Inf", neginf.string = "-Inf", nan.string = "NaN", true = "1", false = "0", title = deparse(substitute(x)), source = "R", version = " ", date = NULL, comment = " ", properties = NULL)
writeSDML(x, file = "", textdata = NULL, dtd = NULL, sep = " 

", na.string = "NA", null.string = "NULL", posinf.string = "+Inf", neginf.string = "-Inf", nan.string = "NaN", true = "1", false = "0", title = deparse(substitute(x)), source = "R", version = " ", date = NULL, comment = " ", properties = NULL)
x |
a data object. |
file |
the name of the file to write to. |
textdata |
save array elements as |
dtd |
location of the StatDataML DTD. |
sep |
field separator for |
na.string |
the string which should be interpreted as |
null.string |
the string which should be interpreted as NULL string. |
posinf.string |
the string which should be interpreted as |
neginf.string |
the string which should be interpreted as |
nan.string |
the string which should be interpreted as
|
true , false
|
the strings which should be interpreted as |
title |
the title of the data being saved (string). |
source |
the source of the data being saved (string). |
version |
the version of the data being saved (string). |
comment |
a free form commentary for the data being saved (string). |
date |
a free form date element, date() by default. |
properties |
an arbitrary list or array. |
info
attributes of arrays are used for the
info
attributes of the e
/ ce
/ na
tags
in StatDataML. For further details on the StatDataML
format see the proposal.
A <- matrix(1:16, ncol=4) rownames(A) <- paste("row", 1:4, sep="") colnames(A) <- paste("col", 1:4, sep="") # export to temporary file tmp_file1 = tempfile() writeSDML(A, tmp_file1) I <- letters[1:16] attr(A, "info") <- I # export to temporary file tmp_file2 = tempfile() writeSDML(A, tmp_file2, textdata = FALSE) # cleanup unlink(tmp_file1) unlink(tmp_file2)
A <- matrix(1:16, ncol=4) rownames(A) <- paste("row", 1:4, sep="") colnames(A) <- paste("col", 1:4, sep="") # export to temporary file tmp_file1 = tempfile() writeSDML(A, tmp_file1) I <- letters[1:16] attr(A, "info") <- I # export to temporary file tmp_file2 = tempfile() writeSDML(A, tmp_file2, textdata = FALSE) # cleanup unlink(tmp_file1) unlink(tmp_file2)