Steven Shafer
2008-Aug-30 14:10 UTC
[R] Saving 3d objects vs. pausing in non-interactive (scripted) mode
I am using the RGL library in scripted (non-interactive) mode, but wish to give the data analyst an opportunity to exam the 3D plots. The "data analysts" understand the data, but not R. My intent is to provide simple Windows (XP) batch files that call R and automatically pass scripts to it, and thus permit the analyst to easily access graphics without having to cut and paste commands into R. This leads to several questions: 1. Is there any way to save the 3D object so that it can later be restored and manipulated without rerunning the script that created it? This would be the ideal solution, so the analyst can simply pull up the 3D object and examine the data at a convenient time. My hope would be that some method would exist to save as a full 3D object the graphic created using rgl, and subsequent call it up with a command along the lines of r < 3dobject.RData -vanilla. 2. A less optimal solution would be to pause the scripted (non-interactive) session while the 3D object is available. In my Windows environment I've tried various suggestions from the archives without success: a. par(ask=TRUE) (requires creating dummy graphs to obtain a pause, since par3d does not support ask) b. readline(prompt = "Pause. Press <Enter> to continue...") c. pause() in the DAAG package d. scan(). e. locator() 3. Here is a test script (pause.txt) showing the above suggestions fail: require(DAAG) X <- seq(0,10) par(ask=TRUE) plot(X,X) pause() locator(type="p") browser() scan() readline(prompt = "Readline pause. Press <Enter> to continue...") plot(x^2~x) I call this with: r < pause.txt - save The file runs from beginning to end without stopping. 4. I do have a very NONELEGANT solution: cat("Press <Control-C> to end (rather crudely)") while (TRUE){} This does work, but it requires exiting R using control-C, which is not very satisfying. Any help would be appreciated, Steve Shafer [[alternative HTML version deleted]]
Duncan Murdoch
2008-Aug-30 23:14 UTC
[R] Saving 3d objects vs. pausing in non-interactive (scripted) mode
On 30/08/2008 10:10 AM, Steven Shafer wrote:> I am using the RGL library in scripted (non-interactive) mode, but wish to > give the data analyst an opportunity to exam the 3D plots. The "data > analysts" understand the data, but not R. My intent is to provide simple > Windows (XP) batch files that call R and automatically pass scripts to it, > and thus permit the analyst to easily access graphics without having to cut > and paste commands into R. This leads to several questions: > > > > 1. Is there any way to save the 3D object so that it can later be > restored and manipulated without rerunning the script that created it? This > would be the ideal solution, so the analyst can simply pull up the 3D object > and examine the data at a convenient time. My hope would be that some method > would exist to save as a full 3D object the graphic created using rgl, and > subsequent call it up with a command along the lines of r < 3dobject.RData > -vanilla.No, there's not. But that would be a nice thing to have. Currently, you need to save the script that created the object, and then run that script.> > > > 2. A less optimal solution would be to pause the scripted > (non-interactive) session while the 3D object is available. In my Windows > environment I've tried various suggestions from the archives without > success: > > a. par(ask=TRUE) (requires creating dummy graphs to obtain a pause, since > par3d does not support ask) > > b. readline(prompt = "Pause. Press <Enter> to continue...") > > c. pause() in the DAAG package > > d. scan(). > > e. locator() > > > > 3. Here is a test script (pause.txt) showing the above suggestions fail: > > require(DAAG) > > X <- seq(0,10) > > par(ask=TRUE) > > plot(X,X) > > pause() > > locator(type="p") > > browser() > > scan() > > readline(prompt = "Readline pause. Press <Enter> to continue...") > > plot(x^2~x) > > > > I call this with: > > r < pause.txt - save > > > > The file runs from beginning to end without stopping. > > > > 4. I do have a very NONELEGANT solution: > > > > cat("Press <Control-C> to end (rather crudely)") > > while (TRUE){}A more elegant variation on this is to attach your own code to the mouse controls (see rgl.setMouseCallbacks), so that the user clicks to shut down. But really, the problem is that you are trying to write a GUI, and R is not very good at that. It's designed to be used by users who are willing to be programmers. One of the slightly clumsy ways to write a GUI in R is to use tcltk; there are others (e.g. RGtk2). See the tkrgl package for sample code that uses tcltk with rgl. Another choice is to write your front-end completely in some other language, and use it to control R. Duncan Murdoch> > > > This does work, but it requires exiting R using control-C, which is not very > satisfying. > > > > Any help would be appreciated, > > > > Steve Shafer > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.