Reputation: 747
I'm trying to write a function to print out a pdf of some graph. I would like my function to take 2 arguments (options): the dataset which I will draw my graphs from and a string variable which is used for the pdf file name. How do I pass the string to a command within the function? my code is :
plot_all_layout <- function(network, filename){
layouts <- grep("^layout_", ls("package:igraph"), value=TRUE)[-1]
# Remove layouts that do not apply to our graph.
layouts <- layouts[!grepl("bipartite|merge|norm|sugiyama|tree", layouts)]
par(mfrow=c(3,3), mar=c(1,1,1,1))
pdf("filename.pdf") #here is where I would like to call the local var
for (layout in layouts) {
print(layout)
l <- do.call(layout, list(network))
plot(network, edge.arrow.mode=0, layout=l, main=layout) }
dev.off()
par(mfrow=c(1,1)
}
Upvotes: 1
Views: 128
Reputation: 924
I think you should use pdf(paste0(filename, ".pdf"))
Hope this helps.
Upvotes: 1