# cteate a GDS file
f <- createfn.gds("test.gds")
(n1 <- add.gdsn(f, "matrix", val=matrix(1:(10*6), nrow=10)))
read.gdsn(index.gdsn(f, "matrix"))
(n2 <- add.gdsn(f, "string",
val=matrix(paste("L", 1:(10*6), sep=","), nrow=10)))
read.gdsn(index.gdsn(f, "string"))
# Apply functions over rows of matrix
apply.gdsn(n1, margin=1, FUN=function(x) print(x), as.is="none")
apply.gdsn(n1, margin=1,
selection = list(rep(c(TRUE, FALSE), 5), rep(c(TRUE, FALSE), 3)),
FUN=function(x) print(x), as.is="none")
apply.gdsn(n1, margin=1, var.index="relative",
selection = list(rep(c(TRUE, FALSE), 5), rep(c(TRUE, FALSE), 3)),
FUN=function(i, x) { cat("index: ", i, ", ", sep=""); print(x) },
as.is="none")
apply.gdsn(n1, margin=1, var.index="absolute",
selection = list(rep(c(TRUE, FALSE), 5), rep(c(TRUE, FALSE), 3)),
FUN=function(i, x) { cat("index: ", i, ", ", sep=""); print(x) },
as.is="none")
apply.gdsn(n2, margin=1, FUN=function(x) print(x), as.is="none")
# Apply functions over columns of matrix
apply.gdsn(n1, margin=2, FUN=function(x) print(x), as.is="none")
apply.gdsn(n1, margin=2,
selection = list(rep(c(TRUE, FALSE), 5), rep(c(TRUE, FALSE), 3)),
FUN=function(x) print(x), as.is="none")
apply.gdsn(n2, margin=2,
selection = list(rep(c(TRUE, FALSE), 5), rep(c(TRUE, FALSE), 3)),
FUN=function(x) print(x), as.is="none")
apply.gdsn(n1, margin=1, FUN=function(x) print(x), as.is="none",
.value=16:40, .substitute=NA)
apply.gdsn(n1, margin=2, FUN=function(x) print(x), as.is="none",
.value=16:40, .substitute=NA)
# close
closefn.gds(f)
########################################################
#
# Append to a target GDS node
#
# cteate a GDS file
f <- createfn.gds("test.gds")
(n2 <- add.gdsn(f, "matrix", val=matrix(1:(10*6), nrow=10)))
(n2 <- add.gdsn(f, "string",
val=matrix(paste("L", 1:(10*6), sep=","), nrow=10)))
read.gdsn(index.gdsn(f, "string"))
n2.1 <- add.gdsn(f, "transpose.matrix", storage="int", valdim=c(6,0))
n2.1 <- add.gdsn(f, "transpose.string", storage="string", valdim=c(6,0))
# Apply functions over rows of matrix
apply.gdsn(n2, margin=1, FUN=`c`, as.is="gdsnode", target.node=n2.1)
# matrix transpose
read.gdsn(n2)
read.gdsn(n2.1)
# Apply functions over rows of matrix
apply.gdsn(n2, margin=1, FUN=`c`, as.is="gdsnode", target.node=n2.1)
# matrix transpose
read.gdsn(n2)
read.gdsn(n2.1)
# close
closefn.gds(f)
########################################################
#
# Append to multiple target GDS node
#
# cteate a GDS file
f <- createfn.gds("test.gds")
(n2 <- add.gdsn(f, "matrix", val=matrix(1:(10*6), nrow=10)))
n2.1 <- add.gdsn(f, "transpose.matrix", storage="int", valdim=c(6,0))
n2.2 <- add.gdsn(f, "n.matrix", storage="int", valdim=c(0))
# Apply functions over rows of matrix
apply.gdsn(n2, margin=1, FUN=function(x) list(x, x[1]),
as.is="gdsnode", target.node=list(n2.1, n2.2))
# matrix transpose
read.gdsn(n2)
read.gdsn(n2.1)
read.gdsn(n2.2)
# close
closefn.gds(f)
########################################################
#
# Multiple variables
#
# cteate a GDS file
f <- createfn.gds("test.gds")
X <- matrix(1:50, nrow=10)
Y <- matrix((1:50)/100, nrow=10)
Z1 <- factor(c(rep(c("ABC", "DEF", "ETD"), 3), "TTT"))
Z2 <- c(TRUE, FALSE, TRUE, FALSE, TRUE)
node.X <- add.gdsn(f, "X", X)
node.Y <- add.gdsn(f, "Y", Y)
node.Z1 <- add.gdsn(f, "Z1", Z1)
node.Z2 <- add.gdsn(f, "Z2", Z2)
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z1), margin=c(1, 1, 1),
FUN=print, as.is="none")
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z2), margin=c(2, 2, 1),
FUN=print)
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z2), margin=c(2, 2, 1),
FUN=print, .value=35:45, .substitute=NA)
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z2), margin=c(2, 2, 1),
FUN=print, .value=35:45, .substitute=NA)
# with selection
s1 <- rep(c(FALSE, TRUE), 5)
s2 <- c(TRUE, FALSE, TRUE, FALSE, TRUE)
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z1), margin=c(1, 1, 1),
selection = list(list(s1, s2), list(s1, s2), list(s1)),
FUN=function(x) print(x))
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z2), margin=c(2, 2, 1),
selection = list(list(s1, s2), list(s1, s2), list(s2)),
FUN=function(x) print(x))
# close the GDS file
closefn.gds(f)
# delete the temporary file
unlink("test.gds", force=TRUE)
Run the code above in your browser using DataLab