1

I have a very simple .r file:

library("rgl")
par(ask=TRUE)

x=c(0.44,0.45)
y=c(0.2, 0.3)
z=matrix(c(1,2,3,4),nrow=length(x))

persp3d(x,y,z)

When I open a cmd screen and navigate to my R installation and try

Rscript P:\pathtoscript\example.r

I see the persp3d graph flash up really quickly and then disappear, even though my .r file contains the par(ask=true) command.

So my question is, how can I keep it up and play around with it, without it going away before I'm done?

Thanks for your help.

user3782261
  • 57
  • 1
  • 8

1 Answers1

1

I'm not aware of a more idiomatic way to do this type of thing, but you can just add Sys.sleep(large_number_of_seconds) to keep the R process alive. For example,

script.R

library("rgl")

x <- c(0.44, 0.45)
y <- c(0.2, 0.3)
z <- matrix(c(1,2,3,4),nrow = length(x))

persp3d(x,y,z)
Sys.sleep(100000)

Also, the ask argument to par is only used in interactive sessions, which is why it was not working here.

nrussell
  • 18,382
  • 4
  • 47
  • 60