2
# This can be used to write out an XML description of one or more
3
# data frames into GGobi's data format.
7
function(..., dom = xmlOutputDOM("ggobidata", attrs = c(count = length(args))))
11
for(i in 1:length(args)) {
12
name <- names(args)[i]
13
# if this is "", use the deparse() version
14
datasetToGGobiXML(args[[i]], name, dom)
21
function(data, name, dom, description = NULL, asElements = TRUE)
24
dom$addTag("data", attrs=c(name=name), close = FALSE)
25
dom$addTag("description", description)
27
dataframe = getData.ggobi(data)
28
dom$addTag("variables", attrs=c(count = ncol(data)), close=FALSE)
29
for(i in names(dataframe)) {
30
if(inherits(dataframe[[i]], "factor")) {
31
dom$addTag("categoricalvariable", attrs = c(name = i), close = FALSE)
32
levs <- levels(dataframe[[i]])
33
dom$addTag("levels", attrs = c(count=length(levs)), close = FALSE)
34
for(j in 1:length(levs)) {
35
dom$addTag("level", paste("\"", levs[j], "\"", sep=""), attrs= c(value=j))
37
dom$closeTag("levels")
38
dom$closeTag("categoricalvariable")
40
dom$addTag("realvariable", attrs = c(name = i))
42
dom$closeTag("variables")
44
dom$addTag("records", attrs =c(count = nrow(data)), close = FALSE)
46
rownames <- dimnames(data)[[1]]
47
edges <- getEdges.ggobi(data)
49
for(i in 1:nrow(data)) {
51
if (nrow(edges) >= i) {
52
recordAttrs <- c(id = i, source = edges[i,1], destination = edges[i,2])
53
} else recordAttrs = c(label = rownames[i], id = rownames[i])
55
# If we want to put <el>value</el><el>value</el> within the <record>
56
# we'll have to do it one at a time!
57
dom$addTag("record", attrs=recordAttrs, close = FALSE)
58
if (is.matrix(data) || is.data.frame(data)) {
61
tag <- switch(typeof(r), double="real", integer="int")
64
} else dom$addNode(xmlTextNode(paste(data[i,], collapse=" ")))
66
dom$closeTag("record")
68
dom$closeTag("records")
73
writeDatasetsXML <- function(filename, .data = 1, .gobi = getDefaultGGobi()) {
74
refs <- lapply(.data, dataset, .gobi)
75
.GGobiCall("writeDatasetsXML", as.character(filename), refs, .gobi = .gobi)