Dear List,
I have a series of nested loops with the structure shown below, and I am
struggling to figure out how to divert output to folders created with
dir.create() within the loops.
What I need is for the output to end up as topNameK/subNameL/objNameM.pdf;
what I get instead is a series of directories topNameK/, directories
subNameL/, and files objNameM.pdf, all in the working directory. Any hints
on how to do this will be much appreciated!
Many thanks in advance,
Lara
for (K in ...){
... create object ...
topDirName <- as.character(paste("topName", K,
sep=""))
topDirMake <- dir.create(topDirName)
for (L in ...) {
subDirName <- as.character(paste("subName", L,
sep=""))
subDirMake <- dir.create(subDirName)
... manipulate object ...
for (M in ...) {
objectName <- as.character(paste("objName", M,
".pdf", sep=""))
pdf(objectName)
plot(object)
dev.off()
}
}
}
[[alternative HTML version deleted]]
Lara Poplarski <larapoplarski at gmail.com> [Wed, Nov 24, 2010 at 06:14:58PM CET]:> for (K in ...){ > > ... create object ... > > topDirName <- as.character(paste("topName", K, sep="")) > topDirMake <- dir.create(topDirName)You may want to insert setwd(topDirName) here.> > for (L in ...) { > > subDirName <- as.character(paste("subName", L, sep="")) > subDirMake <- dir.create(subDirName)and setwd(subDirName) here.> > ... manipulate object ... > > for (M in ...) { > > objectName <- as.character(paste("objName", M, ".pdf", sep="")) > > pdf(objectName) > plot(object) > dev.off() > }and, accordingly, setwd("..") here> }and here> } >-- Johannes H?sing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johannes at huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")