~ubuntu-branches/ubuntu/utopic/rggobi/utopic

« back to all changes in this revision

Viewing changes to R/next-version/writeXML.S

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2006-11-09 20:28:24 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061109202824-rprmht1pviku76qg
Tags: 2.1.4-1-1
* New upstream release
* debian/rules: Simplied to one-liner sourcing r-cran.mk
* debian/control: (Build-)Depends: upgraded to the current versions
  r-base-core (>= 2.4.0) and ggobi (>= 2.1.4)
* debian/control: Added Depends: on r-cran-rgtk2; we cannot currently
  Build-Depends: on it as it wants an X11 display which stop autobuilds
* debian/control: Standards-Version: upgraded to 3.7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# This can be used to write out an XML description of one or more
3
 
# data frames into GGobi's data format.
4
 
#
5
 
 
6
 
toGGobiXML <-
7
 
function(..., dom = xmlOutputDOM("ggobidata", attrs = c(count = length(args))))
8
 
{
9
 
  args <- list(...)
10
 
 
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)
15
 
  }
16
 
 
17
 
  dom
18
 
}
19
 
 
20
 
datasetToGGobiXML <-
21
 
function(data, name, dom, description = NULL, asElements = TRUE)
22
 
{
23
 
 
24
 
  dom$addTag("data", attrs=c(name=name), close = FALSE)
25
 
  dom$addTag("description", description)
26
 
 
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))
36
 
        }
37
 
      dom$closeTag("levels")
38
 
      dom$closeTag("categoricalvariable")
39
 
    } else
40
 
      dom$addTag("realvariable", attrs = c(name = i))
41
 
  }
42
 
  dom$closeTag("variables")
43
 
 
44
 
  dom$addTag("records", attrs =c(count = nrow(data)), close = FALSE)
45
 
 
46
 
  rownames <- dimnames(data)[[1]]
47
 
  edges <- getEdges.ggobi(data)
48
 
 
49
 
  for(i in 1:nrow(data)) {
50
 
 
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])
54
 
 
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)) {
59
 
      if(asElements) {
60
 
         for(r in data[i,]) {
61
 
             tag <- switch(typeof(r), double="real", integer="int")
62
 
             dom$addTag(tag, r)
63
 
         }
64
 
      } else dom$addNode(xmlTextNode(paste(data[i,], collapse=" ")))
65
 
   }
66
 
   dom$closeTag("record")
67
 
  }
68
 
  dom$closeTag("records")
69
 
 
70
 
  dom$closeTag("data")
71
 
}
72
 
 
73
 
writeDatasetsXML <- function(filename, .data = 1, .gobi = getDefaultGGobi()) {
74
 
        refs <- lapply(.data, dataset, .gobi)
75
 
        .GGobiCall("writeDatasetsXML", as.character(filename), refs, .gobi = .gobi)
76
 
}