1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
xgvis <-
function(dmat = NULL,
edges = NULL,
pos = NULL,
rowlab = NULL,
colors = NULL,
glyphs = NULL,
erase = NULL,
lines = NULL,
linecolors = NULL,
resources = NULL,
display = NULL)
{
if (missing(edges) && missing(pos) && missing(dmat)) {
cat("One of dmat, edges, or pos must be present\n")
return()
}
tpath <- getenv("S_TMP")
if(nchar(tpath) == 0) tpath <- getenv("TEMP")
basefile <- paste(tpath, tempfile("xgvis"), sep = "/")
### distance matrix ###
if (!missing(dmat)) {
dmat <- eval(dmat)
if (sum(abs(dmat[!is.na(dmat)])) == Inf > 0) {
cat("xgvis can't handle Infs in dmat, replaced with NA\n")
dmat[dmat==Inf] <- NA
}
dfile <- paste(basefile, ".dist", sep="")
write(t(dmat), file = dfile, ncolumns = ncol(dmat))
on.exit(unlink(dfile), add=T)
}
### Edges ###
if (!missing(edges))
{
# check data type
if (!is.matrix(edges) || !is.numeric(edges) || dim(edges)[2] != 2) {
cat("The 'edges' argument must be a numeric 2-column matrix\n")
return()
}
edgesfile <- paste(basefile, ".edges", sep="")
if (nrow(edges) > 0) {
write(t(edges), file = edgesfile, ncol=2)
}
on.exit(unlink(edgesfile), add=T)
}
### position matrix ###
if (!missing(pos)) {
pos <- eval(pos)
if (sum(abs(pos[!is.na(pos)])) == Inf > 0)
{
cat("xgvis can't handle Inf in pos; replaced with NA\n")
pos[pos==Inf] <- NA
}
pfile <- paste(basefile, ".pos", sep="")
write(t(pos), file = pfile, ncolumns = ncol(pos))
on.exit(unlink(pfile), add = T)
}
### Row labels ###
if (!missing(rowlab))
# check data type
if (!is.vector(rowlab) || !is.character(rowlab)) {
cat("The 'rowlab' argument needs to be a character vector\n")
return()
}
if (length(rowlab) > 0) {
rowfile <- paste(basefile, ".row", sep="")
write(rowlab, file = rowfile, ncol=1)
on.exit(unlink(rowfile), add = T)
}
### Colors ###
if (!missing(colors)) {
# check data type
if (!is.vector(colors) || !is.character(colors)) {
cat("The 'colors' argument needs to be a character vector\n")
return()
}
colorfile <- paste(basefile, ".colors", sep="")
write(colors, file = colorfile, ncol=1)
on.exit(unlink(colorfile), add = T)
}
### Glyphs ###
if (!missing(glyphs)) {
# check data type
if (!is.vector(glyphs) || !is.numeric(glyphs)) {
cat("The 'glyphs' argument needs to be a numeric vector\n")
return()
}
glyphfile <- paste(basefile, ".glyphs", sep="")
write(glyphs, file = glyphfile, ncol=1)
on.exit(unlink(glyphfile), add = T)
}
### Erase ###
if (!missing(erase)) {
# check data type
if (!is.vector(erase) || !is.numeric(erase)) {
cat("The 'erase' argument needs to be a numeric vector\n")
return()
}
erasefile <- paste(basefile, ".erase", sep="")
write(erase, file = erasefile, ncol=1)
on.exit(unlink(erasefile), add = T)
}
### Connected lines ###
if (!missing(lines)) {
# check data type
if (!is.matrix(lines) || !is.numeric(lines) || dim(lines)[2] != 2) {
cat("The 'lines' argument must be a numeric 2-column matrix\n")
return()
}
linesfile <- paste(basefile, ".lines", sep="")
if (nrow(lines) > 0) {
write(t(lines), file = linesfile, ncol=2)
on.exit(unlink(linesfile), add = T)
}
}
### Line colors ###
if ((!missing(lines) || !missing(edges)) && !missing(linecolors)) {
# check data type
if (!is.vector(linecolors) || !is.character(linecolors)) {
cat("The 'linecolors' argument must be a character vector\n")
return()
}
linecolorfile <- paste(basefile, ".linecolors", sep="")
write(linecolors, file = linecolorfile, ncol=1)
on.exit(unlink(linecolorfile), add = T)
}
### Resources ###
if (!missing(resources)) {
# check data type
if (!is.vector(resources) || !is.character(resources)) {
cat("The 'resources' argument must be a character vector\n")
return()
}
resourcefile <- paste(basefile, ".resources", sep="")
write(resources, file = resourcefile, ncol=1)
on.exit(unlink(resourcefile), add = T)
}
# Note to installer:
# Here you need to specify the path to the xgvis batch file/ executable
# on your system.
#
# dos example:
# xgpath <- "c:/packages/xgobi/xgvis.bat"
# unix example:
xgpath <- "/usr/dfs/xgobi/joint/src/xgvis"
command <- paste(xgpath, basefile)
cat(command, "\n")
# dos:
# invisible(dos(command, multi = F, minimized = T, output.to.S = F, translate = T))
# unix:
invisible(unix(command))
}
|