R and plot graphics

Discuss any topics about the editor here

R and plot graphics

Postby measgrad » Wed Mar 02, 2011 9:00 pm

Hi all,

I've been using Editra for R [statistical language] scripting, and for the most part it works very well. It's a much more pleasant experience to write the scripts here than in the R editor. I do, however, have one issue, and an associated question: I've never been able to generate a plot graphic from scripts launched from Editra. The script will run, and all of the non-plot related instructions will execute, text results post to the output window in(on) the shelf, along with a gratifying return code 0 at the end---but the plot graphic never appears. Cutting and pasting everything into the R-command processor produces the text, too, along with the desired graphic, but I can't seem to repeat the action, in full, in Editra. There is no mention in the launch window, nor log, of problems, a missing library, nor any other misstep having occurred during code execution. Does anyone know if it's possible to do this (call the R plot functions from Editra), and if so, would someone be so kind as to explain to me how?

Thanks very much...
measgrad
Limited User
 
Posts: 2
Joined: Wed Mar 02, 2011 8:20 pm

Re: R and plot graphics

Postby cody » Wed Mar 02, 2011 9:14 pm

Hi,

I don't know anything about R but the Launch plugin just runs the given command line command on the file so it should be no different than if you do the same from a command terminal.

Does R output the graphics to stdio?

If so then the graphics are probably in some binary (non-text) format so the text buffer is not able to display the characters for them. What kind of format are the graphics in?

The other possibility is that the graphics are not actually part of the output data and that the R editor is analyzing the output data in order to create the graphs.

What happens if you run the same command from the command line?


Cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: R and plot graphics

Postby measgrad » Thu Mar 03, 2011 5:58 pm

Hi Cody,

Thanks for replying so quickly.

I don't know a great deal about R's inner workings either, but, I know that the graphics display isn't back to stdio. Rather, the graphics request gets assigned to a separate window that's spawned upon issuance of the plot command. For instance, if I type the following in the R-console (command line):

x=c(1:7)
y = c(8:14)
plot(x,y)

a [very nice] graphics window will open displaying a scatter plot of the values contained in the vectors x and y.

From Editra I can launch the same commands, but receive:

>>> Rscript workshop.r

>>> Exit Code: 0

in return. I know that everything executed fine, but no plot window opens.

Thinking that perhaps I must explicitly initialize and open a graphics window, I added the line:

quartz()

to my original script (above). Quartz here is in reference to the Mac OS X 2-D graphics system (I should have mentioned up front that I'm doing all of this on a Macintosh---sorry) which R takes advantage of with OSX. This time, when Editra ran the code, the graphics window was displayed, but only for a fraction of a second. The quartz window flashed on then off, in the [literal] blink of an eye.

Maybe there's a way to keep the Quartz window open? I don't know. Perhaps somewhere, deep down inside the documentation there's an answer. In the meantime, I can write in Editra and, where graphics are involved, call the script up at the R-console to pick up the graphics.

Paul
measgrad
Limited User
 
Posts: 2
Joined: Wed Mar 02, 2011 8:20 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron