emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* R session and plotting in x11 window
@ 2020-04-04 23:27 Matt Price
  2020-04-05 17:19 ` Berry, Charles via General discussions about Org-mode.
  0 siblings, 1 reply; 5+ messages in thread
From: Matt Price @ 2020-04-04 23:27 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 950 bytes --]

Does anyone know much about the difference between an R session opened by
typing M-x R, and the R session opened by org-babel?

I'm just learning R and my usual method for learning a language is to keep
a kind of notebook in org with code snippets they I can execute and iterate
on rapidly as I learn. This works great in R when I'm just doing math.
When I am working on plots, it would be nice to have them open up quickly
either in emacs or in the standard x11 window that R session opened switch
M-x R opens up.

I know I can set the src block headers to produ e a file, but when I'm just
iterating rapidly I often switch back and forth between a data output and a
graphical output, and typing/erasing those headers is clunky and slow. It
would be easier to just paste the plot command into the console and have it
pop open the window... But that doesn't seem to work. Anyone know if I can
tweak something to make that possible?

Thank you!

Matt

[-- Attachment #2: Type: text/html, Size: 1179 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: R session and plotting in x11 window
  2020-04-04 23:27 R session and plotting in x11 window Matt Price
@ 2020-04-05 17:19 ` Berry, Charles via General discussions about Org-mode.
  2020-04-07  1:26   ` Matt Price
  0 siblings, 1 reply; 5+ messages in thread
From: Berry, Charles via General discussions about Org-mode. @ 2020-04-05 17:19 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode



> On Apr 4, 2020, at 4:27 PM, Matt Price <moptop99@gmail.com> wrote:
> 
> Does anyone know much about the difference between an R session opened by typing M-x R, and the R session opened by org-babel?


Short answer: almost none.

Long answer: what `org-babel-R-initite-session' and friends do.

> 
> I'm just learning R and my usual method for learning a language is to keep a kind of notebook in org with code snippets they I can execute and iterate on rapidly as I learn. This works great in R when I'm just doing math.  When I am working on plots, it would be nice to have them open up quickly either in emacs or in the standard x11 window that R session opened switch M-x R opens up.  
> 
> I know I can set the src block headers to produ e a file, but when I'm just iterating rapidly I often switch back and forth between a data output and a graphical output, and typing/erasing those headers is clunky and slow. It would be easier to just paste the plot command into the console and have it pop open the window... But that doesn't seem to work. Anyone know if I can tweak something to make that possible?
> 


I sam really puzzled by this. Do you have an ECM that illustrates this?

Working interactively on my Mac (Quartz - X11 is the device), I routinely do what you describe - usually working from the src edit buffer - and the plots are displayed (and older plots are available via clover-left or some such).

If I had to guess, I'd say that you are opening an R session, but not using it. If you execute a src block, but it does not have a `:session' header, a new instance of R will create a plot file and then exit. If you look in the default directory, you would see `Rplots.pdf' or some such.

The only other thing that comes to mind is that you opened a device that is holding on to all your plots. Try `dev.cur()' in R immediately before and after you create a plot and see what the result is.

HTH,

Chuck




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: R session and plotting in x11 window
  2020-04-05 17:19 ` Berry, Charles via General discussions about Org-mode.
@ 2020-04-07  1:26   ` Matt Price
  2020-04-07 11:36     ` briangpowell .
  2020-04-07 17:37     ` Berry, Charles via General discussions about Org-mode.
  0 siblings, 2 replies; 5+ messages in thread
From: Matt Price @ 2020-04-07  1:26 UTC (permalink / raw)
  To: Berry, Charles; +Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 2830 bytes --]

On Sun, Apr 5, 2020 at 1:19 PM Berry, Charles <ccberry@health.ucsd.edu>
wrote:

>
>
> > On Apr 4, 2020, at 4:27 PM, Matt Price <moptop99@gmail.com> wrote:
> >
> > Does anyone know much about the difference between an R session opened
> by typing M-x R, and the R session opened by org-babel?
>
>
> Short answer: almost none.
>
> Long answer: what `org-babel-R-initite-session' and friends do.
>
:-) thanks, I should have been looking for that

>
> >
> > I'm just learning R and my usual method for learning a language is to
> keep a kind of notebook in org with code snippets they I can execute and
> iterate on rapidly as I learn. This works great in R when I'm just doing
> math.  When I am working on plots, it would be nice to have them open up
> quickly either in emacs or in the standard x11 window that R session opened
> switch M-x R opens up.
> >
> > I know I can set the src block headers to produ e a file, but when I'm
> just iterating rapidly I often switch back and forth between a data output
> and a graphical output, and typing/erasing those headers is clunky and
> slow. It would be easier to just paste the plot command into the console
> and have it pop open the window... But that doesn't seem to work. Anyone
> know if I can tweak something to make that possible?
> >
>
>
> I sam really puzzled by this. Do you have an ECM that illustrates this?
>
> Working interactively on my Mac (Quartz - X11 is the device), I routinely
> do what you describe - usually working from the src edit buffer - and the
> plots are displayed (and older plots are available via clover-left or some
> such).
>
> If I had to guess, I'd say that you are opening an R session, but not
> using it. If you execute a src block, but it does not have a `:session'
> header, a new instance of R will create a plot file and then exit. If you
> look in the default directory, you would see `Rplots.pdf' or some such.
>
> The only other thing that comes to mind is that you opened a device that
> is holding on to all your plots. Try `dev.cur()' in R immediately before
> and after you create a plot and see what the result is.
>
> This was the problem. I don't see that I'm calling dev.set() anywhere but
when the session initiates dev.cur() returns

null
     1

calling dev.set(1) or dev.set(2) launches an R_x11 window and future plots
are displayed there.  As I say, I'm just learning R, and I don't really
understand how the device is set up. I also don't understand why it would
be set to X11 in a plain-old R session, but not in an org-babel R session.
Most references to "device" in ~ob-R.el~ seem to be managing file outputs,
and "X11". For now I don't think I'll explore  a proper solution as I'm
already pretty far down a rabit hole just learning R at all!  But thanks
very much for this workaround.

Matt

> HTH,
>
> Chuck
>
>
>

[-- Attachment #2: Type: text/html, Size: 3851 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: R session and plotting in x11 window
  2020-04-07  1:26   ` Matt Price
@ 2020-04-07 11:36     ` briangpowell .
  2020-04-07 17:37     ` Berry, Charles via General discussions about Org-mode.
  1 sibling, 0 replies; 5+ messages in thread
From: briangpowell . @ 2020-04-07 11:36 UTC (permalink / raw)
  To: Matt Price; +Cc: Berry, Charles, Org Mode

[-- Attachment #1: Type: text/plain, Size: 3863 bytes --]

"I also don't understand why it would be set to X11 in a plain-old R
session"

R is an open source derivative of S and S-PLUS--"S" was the "Statistics
Language"

MIT X Consortium's "X Motif" is the default output of R from its inception

R, S, S-PLUS have always made such output as its default

Suggest you just "get with the program"--thousands of R libraries are ready
for you to use, extend and create your own libraries if you like--all
leveraging the power of X11R6 --i.e. the XWindows system:
https://en.wikipedia.org/wiki/X_Window_System

By the way Micro$oft Windows is based on MIT's W--W stood for Windows--yet
another thing MicroSoft swiped and monopolized and then sued others about
whenever possible--rather than join the open source & free software movement

X11 is free & open source--all the best software is free & open
source--like Emacs Org-Mode



On Mon, Apr 6, 2020 at 9:27 PM Matt Price <moptop99@gmail.com> wrote:

>
>
> On Sun, Apr 5, 2020 at 1:19 PM Berry, Charles <ccberry@health.ucsd.edu>
> wrote:
>
>>
>>
>> > On Apr 4, 2020, at 4:27 PM, Matt Price <moptop99@gmail.com> wrote:
>> >
>> > Does anyone know much about the difference between an R session opened
>> by typing M-x R, and the R session opened by org-babel?
>>
>>
>> Short answer: almost none.
>>
>> Long answer: what `org-babel-R-initite-session' and friends do.
>>
> :-) thanks, I should have been looking for that
>
>>
>> >
>> > I'm just learning R and my usual method for learning a language is to
>> keep a kind of notebook in org with code snippets they I can execute and
>> iterate on rapidly as I learn. This works great in R when I'm just doing
>> math.  When I am working on plots, it would be nice to have them open up
>> quickly either in emacs or in the standard x11 window that R session opened
>> switch M-x R opens up.
>> >
>> > I know I can set the src block headers to produ e a file, but when I'm
>> just iterating rapidly I often switch back and forth between a data output
>> and a graphical output, and typing/erasing those headers is clunky and
>> slow. It would be easier to just paste the plot command into the console
>> and have it pop open the window... But that doesn't seem to work. Anyone
>> know if I can tweak something to make that possible?
>> >
>>
>>
>> I sam really puzzled by this. Do you have an ECM that illustrates this?
>>
>> Working interactively on my Mac (Quartz - X11 is the device), I routinely
>> do what you describe - usually working from the src edit buffer - and the
>> plots are displayed (and older plots are available via clover-left or some
>> such).
>>
>> If I had to guess, I'd say that you are opening an R session, but not
>> using it. If you execute a src block, but it does not have a `:session'
>> header, a new instance of R will create a plot file and then exit. If you
>> look in the default directory, you would see `Rplots.pdf' or some such.
>>
>> The only other thing that comes to mind is that you opened a device that
>> is holding on to all your plots. Try `dev.cur()' in R immediately before
>> and after you create a plot and see what the result is.
>>
>> This was the problem. I don't see that I'm calling dev.set() anywhere but
> when the session initiates dev.cur() returns
>
> null
>      1
>
> calling dev.set(1) or dev.set(2) launches an R_x11 window and future plots
> are displayed there.  As I say, I'm just learning R, and I don't really
> understand how the device is set up. I also don't understand why it would
> be set to X11 in a plain-old R session, but not in an org-babel R session.
> Most references to "device" in ~ob-R.el~ seem to be managing file outputs,
> and "X11". For now I don't think I'll explore  a proper solution as I'm
> already pretty far down a rabit hole just learning R at all!  But thanks
> very much for this workaround.
>
> Matt
>
>> HTH,
>>
>> Chuck
>>
>>
>>

[-- Attachment #2: Type: text/html, Size: 5423 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: R session and plotting in x11 window
  2020-04-07  1:26   ` Matt Price
  2020-04-07 11:36     ` briangpowell .
@ 2020-04-07 17:37     ` Berry, Charles via General discussions about Org-mode.
  1 sibling, 0 replies; 5+ messages in thread
From: Berry, Charles via General discussions about Org-mode. @ 2020-04-07 17:37 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

Matt,

I am glad you got past your roadblock.

I am puzzled by your use of `dev.set'. I have never explicitly invoked that function. 

FWIW, I have used R for more than 20 years and routinely write packages or reports that create graphics.

And I use ESS (and used its predecessor S-mode) as my principal IDE for that work. (Org relies on ESS for modes relating to R.) I routinely use Mac OS, but occasionally work with Linux and Windows.

Invoking R from the terminal window (or equivalent on Windows) and typing interactive commands, I get:

> dev.cur()
null device 
          1 
> plot(1:5)
> dev.cur()
quartz 
     2 
> 

Note there is no call to dev.set(). 

The quartz device (the interactive default on Mac OS) is invoked implicitly by plot as described by the `Details' in the help page displayed by typing `?device' as the R prompt"

"If no device is open, calling any high-level graphics function will cause a device to be opened."

If I start emacs and open an org buffer with just this src block in it:

#+begin_src R
  dev.cur()
  plot(1:5)
  dev.cur()
#+end_src

then place point in the src block and type the line in this example block

#+begin_example
C-c ' C-n RET C-n C-n
#+end_example

I end up with the same output as above in my *R* session buffer. A new graphics device is opened and the plot appears in it.


Best,

Chuck

> On Apr 6, 2020, at 6:26 PM, Matt Price <moptop99@gmail.com> wrote:
> 
> 
> 
> On Sun, Apr 5, 2020 at 1:19 PM Berry, Charles <ccberry@health.ucsd.edu> wrote:
> 
> 
> > On Apr 4, 2020, at 4:27 PM, Matt Price <moptop99@gmail.com> wrote:
> > 
> > Does anyone know much about the difference between an R session opened by typing M-x R, and the R session opened by org-babel?
> 
> 
> Short answer: almost none.
> 
> Long answer: what `org-babel-R-initite-session' and friends do.
> :-) thanks, I should have been looking for that 
> 
> > 
> > I'm just learning R and my usual method for learning a language is to keep a kind of notebook in org with code snippets they I can execute and iterate on rapidly as I learn. This works great in R when I'm just doing math.  When I am working on plots, it would be nice to have them open up quickly either in emacs or in the standard x11 window that R session opened switch M-x R opens up.  
> > 
> > I know I can set the src block headers to produ e a file, but when I'm just iterating rapidly I often switch back and forth between a data output and a graphical output, and typing/erasing those headers is clunky and slow. It would be easier to just paste the plot command into the console and have it pop open the window... But that doesn't seem to work. Anyone know if I can tweak something to make that possible?
> > 
> 
> 
> I sam really puzzled by this. Do you have an ECM that illustrates this?
> 
> Working interactively on my Mac (Quartz - X11 is the device), I routinely do what you describe - usually working from the src edit buffer - and the plots are displayed (and older plots are available via clover-left or some such).
> 
> If I had to guess, I'd say that you are opening an R session, but not using it. If you execute a src block, but it does not have a `:session' header, a new instance of R will create a plot file and then exit. If you look in the default directory, you would see `Rplots.pdf' or some such.
> 
> The only other thing that comes to mind is that you opened a device that is holding on to all your plots. Try `dev.cur()' in R immediately before and after you create a plot and see what the result is.
> 
> This was the problem. I don't see that I'm calling dev.set() anywhere but when the session initiates dev.cur() returns
> 
> null
>      1
> 
> calling dev.set(1) or dev.set(2) launches an R_x11 window and future plots are displayed there.  As I say, I'm just learning R, and I don't really understand how the device is set up. I also don't understand why it would be set to X11 in a plain-old R session, but not in an org-babel R session. Most references to "device" in ~ob-R.el~ seem to be managing file outputs, and "X11". For now I don't think I'll explore  a proper solution as I'm already pretty far down a rabit hole just learning R at all!  But thanks very much for this workaround. 
> 
> Matt
> HTH,
> 
> Chuck




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-07 17:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-04 23:27 R session and plotting in x11 window Matt Price
2020-04-05 17:19 ` Berry, Charles via General discussions about Org-mode.
2020-04-07  1:26   ` Matt Price
2020-04-07 11:36     ` briangpowell .
2020-04-07 17:37     ` Berry, Charles via General discussions about Org-mode.

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).