emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Exporting output and graphics from R
@ 2013-05-30 12:07 SabreWolfy
  2013-05-30 12:24 ` Sebastien Vauban
  0 siblings, 1 reply; 8+ messages in thread
From: SabreWolfy @ 2013-05-30 12:07 UTC (permalink / raw)
  To: emacs-orgmode

When the following code is evaluated or exported, only the link to
"testout.png" appears in the RESULTS section.

--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC R :results output graphics :file testout.png :exports both
plot(1:10, 1:10)
x <- 1:10
library(ascii)
options(asciiType = "org")
ascii(x)
#+END_SRC
--8<---------------cut here---------------end--------------->8---

When this code is evaluated, the value of "x" appears in the RESULTS:

--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC R :results output :exports both
x <- 1:10
library(ascii)
options(asciiType = "org")
ascii(x)                                                                      
#+END_SRC    
--8<---------------cut here---------------end--------------->8---

How can I get the first example to output both graphics and ascii output?
I'm using Org 7.9.2.

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

* Re: Exporting output and graphics from R
  2013-05-30 12:07 Exporting output and graphics from R SabreWolfy
@ 2013-05-30 12:24 ` Sebastien Vauban
  2013-05-30 12:47   ` Rainer M. Krug
  2013-05-31 12:13   ` SabreWolfy
  0 siblings, 2 replies; 8+ messages in thread
From: Sebastien Vauban @ 2013-05-30 12:24 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi SabreWolfy,

SabreWolfy wrote:
> When the following code is evaluated or exported, only the link to
> "testout.png" appears in the RESULTS section.
>
> #+BEGIN_SRC R :results output graphics :file testout.png :exports both
> plot(1:10, 1:10)
> x <- 1:10
> library(ascii)
> options(asciiType = "org")
> ascii(x)
> #+END_SRC

Removing `output' here should solve the above point.

> When this code is evaluated, the value of "x" appears in the RESULTS:
>
> #+BEGIN_SRC R :results output :exports both
> x <- 1:10
> library(ascii)
> options(asciiType = "org")
> ascii(x)
> #+END_SRC
>
> How can I get the first example to output both graphics and ascii output?

AFAICT, you can't have both at the same time. Do you have a real use case for
this?

If really needed, you can define your code once, wrap it with some value for
the ":results" header, and "copy" it somewhere else via Noweb's facility,
where it can be evaluated under other values for the ":results" header.

> I'm using Org 7.9.2.

Try upgrading now to Org 8 so that you fiddle only once with the export
variables -- which changed, even if similar, between Org 7.9 and Org 8.

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: Exporting output and graphics from R
  2013-05-30 12:24 ` Sebastien Vauban
@ 2013-05-30 12:47   ` Rainer M. Krug
  2013-05-30 13:15     ` Feng Shu
  2013-05-31 12:13   ` SabreWolfy
  1 sibling, 1 reply; 8+ messages in thread
From: Rainer M. Krug @ 2013-05-30 12:47 UTC (permalink / raw)
  To: emacs-orgmode

"Sebastien Vauban" <sva-news@mygooglest.com>
writes:

> Hi SabreWolfy,
>
> SabreWolfy wrote:
>> When the following code is evaluated or exported, only the link to
>> "testout.png" appears in the RESULTS section.
>>
>> #+BEGIN_SRC R :results output graphics :file testout.png :exports both
>> plot(1:10, 1:10)
>> x <- 1:10
>> library(ascii)
>> options(asciiType = "org")
>> ascii(x)
>> #+END_SRC
>
> Removing `output' here should solve the above point.
>
>> When this code is evaluated, the value of "x" appears in the RESULTS:
>>
>> #+BEGIN_SRC R :results output :exports both
>> x <- 1:10
>> library(ascii)
>> options(asciiType = "org")
>> ascii(x)
>> #+END_SRC
>>
>> How can I get the first example to output both graphics and ascii output?
>
> AFAICT, you can't have both at the same time. Do you have a real use case for
> this?

Not directly, But I used the following approach to include pdf as well
as jpeg ion a document.

You simply have to create your graph in R and then include a link in org
manually:

,----
| #+BEGIN_SRC R :results output :exports both
| png("testout.png")
| plot(1:10, 1:10)
| dev.off()
| x <- 1:10
| library(ascii)
| options(asciiType = "org")
| ascii(x)          
| #+END_SRC
| 
| 
| [[./testout.png]]
`----

you will get the code, result (output) and the graph (tested on export
to pdf).

Cheers,

Rainer

>
> If really needed, you can define your code once, wrap it with some value for
> the ":results" header, and "copy" it somewhere else via Noweb's facility,
> where it can be evaluated under other values for the ":results" header.
>
>> I'm using Org 7.9.2.
>
> Try upgrading now to Org 8 so that you fiddle only once with the export
> variables -- which changed, even if similar, between Org 7.9 and Org 8.
>
> Best regards,
>   Seb
<#secure method=pgpmime mode=sign>

-- 
Rainer M. Krug

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

* Re: Exporting output and graphics from R
  2013-05-30 12:47   ` Rainer M. Krug
@ 2013-05-30 13:15     ` Feng Shu
  2013-05-30 13:37       ` Rainer M. Krug
  2013-05-31 12:15       ` SabreWolfy
  0 siblings, 2 replies; 8+ messages in thread
From: Feng Shu @ 2013-05-30 13:15 UTC (permalink / raw)
  To: emacs-orgmode

Rainer@krugs.de (Rainer M. Krug) writes:

> "Sebastien Vauban" <sva-news@mygooglest.com>
> writes:
>
>> Hi SabreWolfy,
>>
>> SabreWolfy wrote:
>>> When the following code is evaluated or exported, only the link to
>>> "testout.png" appears in the RESULTS section.
>>>
>>> #+BEGIN_SRC R :results output graphics :file testout.png :exports both
>>> plot(1:10, 1:10)
>>> x <- 1:10
>>> library(ascii)
>>> options(asciiType = "org")
>>> ascii(x)
>>> #+END_SRC
>>
>> Removing `output' here should solve the above point.
>>
>>> When this code is evaluated, the value of "x" appears in the RESULTS:
>>>
>>> #+BEGIN_SRC R :results output :exports both
>>> x <- 1:10
>>> library(ascii)
>>> options(asciiType = "org")
>>> ascii(x)
>>> #+END_SRC
>>>
>>> How can I get the first example to output both graphics and ascii output?
>>
>> AFAICT, you can't have both at the same time. Do you have a real use case for
>> this?
>
> Not directly, But I used the following approach to include pdf as well
> as jpeg ion a document.
>
> You simply have to create your graph in R and then include a link in org
> manually:
>
> ,----
> | #+BEGIN_SRC R :results output :exports both
> | png("testout.png")
> | plot(1:10, 1:10)
> | dev.off()
> | x <- 1:10
> | library(ascii)
> | options(asciiType = "org")
> | ascii(x)          
> | #+END_SRC
> | 
> | 
> | [[./testout.png]]
> `----
>


 #+BEGIN_SRC R :results output :exports both
 pngname <- "testout.png"
 png(pngname)
 plot(1:10, 1:10)
 dev.off()
 x <- 1:10
 paste("[[./", pngname, "]]",sep="")
 #+END_SRC



> you will get the code, result (output) and the graph (tested on export
> to pdf).
>
> Cheers,
>
> Rainer
>
>>
>> If really needed, you can define your code once, wrap it with some value for
>> the ":results" header, and "copy" it somewhere else via Noweb's facility,
>> where it can be evaluated under other values for the ":results" header.
>>
>>> I'm using Org 7.9.2.
>>
>> Try upgrading now to Org 8 so that you fiddle only once with the export
>> variables -- which changed, even if similar, between Org 7.9 and Org 8.
>>
>> Best regards,
>>   Seb
> <#secure method=pgpmime mode=sign>
>

-- 

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

* Re: Exporting output and graphics from R
  2013-05-30 13:15     ` Feng Shu
@ 2013-05-30 13:37       ` Rainer M. Krug
  2013-05-31 12:15       ` SabreWolfy
  1 sibling, 0 replies; 8+ messages in thread
From: Rainer M. Krug @ 2013-05-30 13:37 UTC (permalink / raw)
  To: emacs-orgmode

Feng Shu <tumashu@gmail.com> writes:

> Rainer@krugs.de (Rainer M. Krug) writes:
>
>> "Sebastien Vauban" <sva-news@mygooglest.com>
>> writes:
>>
>>> Hi SabreWolfy,
>>>
>>> SabreWolfy wrote:
>>>> When the following code is evaluated or exported, only the link to
>>>> "testout.png" appears in the RESULTS section.
>>>>
>>>> #+BEGIN_SRC R :results output graphics :file testout.png :exports both
>>>> plot(1:10, 1:10)
>>>> x <- 1:10
>>>> library(ascii)
>>>> options(asciiType = "org")
>>>> ascii(x)
>>>> #+END_SRC
>>>
>>> Removing `output' here should solve the above point.
>>>
>>>> When this code is evaluated, the value of "x" appears in the RESULTS:
>>>>
>>>> #+BEGIN_SRC R :results output :exports both
>>>> x <- 1:10
>>>> library(ascii)
>>>> options(asciiType = "org")
>>>> ascii(x)
>>>> #+END_SRC
>>>>
>>>> How can I get the first example to output both graphics and ascii output?
>>>
>>> AFAICT, you can't have both at the same time. Do you have a real use case for
>>> this?
>>
>> Not directly, But I used the following approach to include pdf as well
>> as jpeg ion a document.
>>
>> You simply have to create your graph in R and then include a link in org
>> manually:
>>
>> ,----
>> | #+BEGIN_SRC R :results output :exports both
>> | png("testout.png")
>> | plot(1:10, 1:10)
>> | dev.off()
>> | x <- 1:10
>> | library(ascii)
>> | options(asciiType = "org")
>> | ascii(x)          
>> | #+END_SRC
>> | 
>> | 
>> | [[./testout.png]]
>> `----
>>
>
>
>  #+BEGIN_SRC R :results output :exports both
>  pngname <- "testout.png"
>  png(pngname)
>  plot(1:10, 1:10)
>  dev.off()
>  x <- 1:10
>  paste("[[./", pngname, "]]",sep="")
>  #+END_SRC
>

There are many ways to kill a bird - but you are right - this one is
nicer. You could even use an org variable to specify the file name.

Cheers,

Rainer


>
>
>> you will get the code, result (output) and the graph (tested on export
>> to pdf).
>>
>> Cheers,
>>
>> Rainer
>>
>>>
>>> If really needed, you can define your code once, wrap it with some value for
>>> the ":results" header, and "copy" it somewhere else via Noweb's facility,
>>> where it can be evaluated under other values for the ":results" header.
>>>
>>>> I'm using Org 7.9.2.
>>>
>>> Try upgrading now to Org 8 so that you fiddle only once with the export
>>> variables -- which changed, even if similar, between Org 7.9 and Org 8.
>>>
>>> Best regards,
>>>   Seb
>> <#secure method=pgpmime mode=sign>
>>
>
<#secure method=pgpmime mode=sign>

-- 
Rainer M. Krug

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

* Re: Exporting output and graphics from R
  2013-05-30 12:24 ` Sebastien Vauban
  2013-05-30 12:47   ` Rainer M. Krug
@ 2013-05-31 12:13   ` SabreWolfy
  2013-05-31 12:25     ` Sebastien Vauban
  1 sibling, 1 reply; 8+ messages in thread
From: SabreWolfy @ 2013-05-31 12:13 UTC (permalink / raw)
  To: emacs-orgmode

Sebastien Vauban <sva-news@...> writes:

> AFAICT, you can't have both at the same time. Do you have a real
> use case for this?

Maybe I'm not using the right tool for the job. I thought it would be useful
to be able to intersperse explanatory text with output:

--8<---------------cut here---------------start------------->8---
All crows are black. We know this from looking at crows. I analyzed a
dataset using this code, and produced a graph as follows:

#+BEGIN_SRC R :results graphics :file testout.png :exports both
# load data, analyze, make graph
#+END_SRC

The above analysis shows that all crows are black. A table of observed
results is as follows:

#+BEGIN_SRC R :results
# more R code using the same dataset
# will only work if the dataset is loaded again
#+END_SRC

This can be summarized with the following results:
#+BEGIN_SRC R :results graphics :file testout.png :exports both
# R code plotting another graph and showing another output table
#+END_SRC
--8<---------------cut here---------------end--------------->8---

My idea is that I would like the R code included for my reference when
reading the document. I would also like the explanatory text, etc. included,
as well as the output and results for the people who will be reading the
document.

Easier just to do it all in LaTeX directly? But then the code is not live,
like it is in Org.

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

* Re: Exporting output and graphics from R
  2013-05-30 13:15     ` Feng Shu
  2013-05-30 13:37       ` Rainer M. Krug
@ 2013-05-31 12:15       ` SabreWolfy
  1 sibling, 0 replies; 8+ messages in thread
From: SabreWolfy @ 2013-05-31 12:15 UTC (permalink / raw)
  To: emacs-orgmode

Feng Shu <tumashu <at> gmail.com> writes:

>  #+BEGIN_SRC R :results output :exports both
>  pngname <- "testout.png"
>  png(pngname)
>  plot(1:10, 1:10)
>  dev.off()
>  x <- 1:10
>  paste("[[./", pngname, "]]",sep="")
>  #+END_SRC

Thanks. This is a great suggestion.

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

* Re: Exporting output and graphics from R
  2013-05-31 12:13   ` SabreWolfy
@ 2013-05-31 12:25     ` Sebastien Vauban
  0 siblings, 0 replies; 8+ messages in thread
From: Sebastien Vauban @ 2013-05-31 12:25 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

SabreWolfy,

SabreWolfy wrote:
> Sebastien Vauban <sva-news@...> writes:
>> AFAICT, you can't have both at the same time. Do you have a real
>> use case for this?
>
> Maybe I'm not using the right tool for the job. I thought it would be useful
> to be able to intersperse explanatory text with output:
>
> All crows are black. We know this from looking at crows. I analyzed a
> dataset using this code, and produced a graph as follows:
>
> #+BEGIN_SRC R :results graphics :file testout.png :exports both
> # load data, analyze, make graph
> #+END_SRC
>
> The above analysis shows that all crows are black. A table of observed
> results is as follows:
>
> #+BEGIN_SRC R :results
> # more R code using the same dataset
> # will only work if the dataset is loaded again
> #+END_SRC
                          ^^^^^^^^^^^^^^^^^^^^^^^
because you don't use the ":session" header argument. Look at it.

> This can be summarized with the following results:
> #+BEGIN_SRC R :results graphics :file testout.png :exports both
> # R code plotting another graph and showing another output table
> #+END_SRC

Use ":noweb yes" and references to named code blocks.

> My idea is that I would like the R code included for my reference when
> reading the document. I would also like the explanatory text, etc. included,
> as well as the output and results for the people who will be reading the
> document.

Of course, that's the whole point of using Org + Babel. Thanks Eric and Dan,
once again...

> Easier just to do it all in LaTeX directly? But then the code is not live,
> like it is in Org.

N/A

Best regards,
  Seb

-- 
Sebastien Vauban

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

end of thread, other threads:[~2013-05-31 12:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-30 12:07 Exporting output and graphics from R SabreWolfy
2013-05-30 12:24 ` Sebastien Vauban
2013-05-30 12:47   ` Rainer M. Krug
2013-05-30 13:15     ` Feng Shu
2013-05-30 13:37       ` Rainer M. Krug
2013-05-31 12:15       ` SabreWolfy
2013-05-31 12:13   ` SabreWolfy
2013-05-31 12:25     ` Sebastien Vauban

Code repositories for project(s) associated with this public 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).