R/Windows Commands

From QERM Wiki
(Redirected from R/Window Commands)
Jump to: navigation, search
MyTrippyPlot.png

Sometimes you might want to run a program in Windows from inside R. Most commonly, I need this to view pdf's that I've just made. This is done with the "shell" command. To open a file, use "start" within the shell. So:

pdf("MyTrippyPlot.pdf", width=18)
par(bg="black", mar=c(0,0,0,0))
matplot(outer(seq(-3*pi,3*pi,len=1000),seq(0,pi,len=1000),f <- function(x,y) sin(x^2)/cos(y^2) * exp(-x^2/10)),
			col=heat.colors(1000), type="l", lwd=2, lty=1)
dev.off()
shell("start MyTrippyPlot.pdf")

All that might be old hat. But I was always a little irritated by needing to manually close the pdf before viewing a newly tweaked one. A solution for that is the shell command "tskill foo" where "foo" is the pdf viewer (or whatever program you want to kill). So now, if I run all of this:

shell("tskill acrobat")

pdf("MyTrippyPlot.pdf", width=12)
par(bg="black", mar=c(0,0,0,0))
matplot(outer(seq(-3*pi,3*pi,len=1000),seq(0,pi,len=1000),f <- function(x,y) sin(x^2)/cos(y^2) * exp(-x^2/10)),
			col=heat.colors(1000), type="l", lwd=2, lty=1)
dev.off()
shell("start MyTrippyPlot.pdf")

the pdf closes and opens without complaints, and I can work on it indefinitely without ever needing to leave the text program / R interface. Remember: every precious click is sacred!

If anyone knows how to close just an instance within acrobat (or reader (or any arbitrary program)) without closing the whole thing, do share!

As good a starting point as any to find useful DOS commands is here.

Personal tools