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]]

