How to get a file associated with a graphics device?

When printing a graph to a file, I want to find the location of the file that I am printing.

pdf("test.pdf")
plot(1:5)
# Somehow retrieve "test.pdf"
dev.off()

In this example, I indicated the file name when I named pdf, so the answer is obvious. My use case is when a file location was automatically generated, for example in a knitr document.

To connect files, you can get the linked file with summary(conn)$description. I was hoping to get something useful from summary(dev.cur())or str(dev.cur()), but you're out of luck.

How can I go from dev.cur()to a linked file? Alternatively, how can I get the location of the file to which the chart is written?

+4
source share
1 answer

, . .Devices :

pdf()
.Devices
#[[1]]
#[1] "null device"
#[[2]]
#[1] "pdf"
#attr(,"filepath")
#[1] "Rplots.pdf"
#[[3]]
#[1] ""

, .

@RichieCotton, "" .Device ( ), , :

attr(.Device, "filepath")
#[1] "Rplots.pdf"
+6

All Articles