* No results when combining :session *R* with print.xtable
@ 2016-03-10 19:11 Stephan Lindner
2016-03-16 17:56 ` John Hendy
0 siblings, 1 reply; 2+ messages in thread
From: Stephan Lindner @ 2016-03-10 19:11 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
Hi,
I encounter the following problem (org version 8.3.2):
When I have the following R source code block in my org file:
#+BEGIN_SRC R :exports results :results replace output latex :eval export
library(xtable)
print(xtable(matrix(c(1,2,3), nrow=1)),
only.contents=TRUE, include.rownames=FALSE, include.colnames=FALSE, comment=FALSE, hline.after=NULL)
#+END_SRC
and I evaluate it, I get the expected result:
#+RESULTS:
#+BEGIN_LaTeX
1.00 & 2.00 & 3.00 \\
#+END_LaTeX
However, when I also include the =:session *R*= in my header, I get this:
#+BEGIN_SRC R :session *R* :exports results :results replace output latex :eval export
library(xtable)
print(xtable(matrix(c(1,2,3), nrow=1)),
only.contents=TRUE, include.rownames=FALSE, include.colnames=FALSE, comment=FALSE, hline.after=NULL)
#+END_SRC
#+RESULTS:
#+BEGIN_LaTeX
#+END_LaTeX
I.e., no result. However, when evaluating the code in R it works (i.e., R prints out =1.00 & 2.00 & 3.00 \\=).
I need to have =:session *R*= in the header because I want to print results of previous calculations in R. I would like
to not have =\hlines= in my LaTeX output (I integrate the result into a LaTeX table).
This problem does not occur when I set =hline.after= to a non-NULL value, e.g.:
#+BEGIN_SRC R :session *R* :exports results :results replace output latex :eval export
library(xtable)
print(xtable(matrix(c(1,2,3), nrow=1)),
only.contents=TRUE, include.rownames=FALSE, include.colnames=FALSE, comment=FALSE, hline.after=1)
#+END_SRC
#+RESULTS:
#+BEGIN_LaTeX
1.00 & 2.00 & 3.00 \\
\hline
#+END_LaTeX
Thanks!
Stephan
--
Stephan Lindner, Ph.D.
Oregon Health and Science University
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: No results when combining :session *R* with print.xtable
2016-03-10 19:11 No results when combining :session *R* with print.xtable Stephan Lindner
@ 2016-03-16 17:56 ` John Hendy
0 siblings, 0 replies; 2+ messages in thread
From: John Hendy @ 2016-03-16 17:56 UTC (permalink / raw)
To: Stephan Lindner; +Cc: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 2120 bytes --]
On Thu, Mar 10, 2016 at 1:11 PM, Stephan Lindner <lindners@ohsu.edu> wrote:
> Hi,
>
> I encounter the following problem (org version 8.3.2):
[snip]
> However, when I also include the =:session *R*= in my header, I get this:
>
> #+BEGIN_SRC R :session *R* :exports results :results replace output latex :eval export
> library(xtable)
> print(xtable(matrix(c(1,2,3), nrow=1)),
> only.contents=TRUE, include.rownames=FALSE, include.colnames=FALSE, comment=FALSE, hline.after=NULL)
> #+END_SRC
>
> #+RESULTS:
> #+BEGIN_LaTeX
> #+END_LaTeX
>
> I.e., no result. However, when evaluating the code in R it works (i.e., R prints out =1.00 & 2.00 & 3.00 \\=).
I can reproduce, and played around with a few things but none worked
very well. I tried using :results output wrap and manually printing
the #+begin_export latex lines myself, but couldn't get the full
output (just the printed #+begin line which seemed to ignore the
xtable() bit afterward).
What about using ascii instead? See attached for the equivalent if it
would work for you. It creates the table directly in Org-mode table
syntax vs. the raw latex. Not sure if that cramps your style with
respect to your full document and what you're doing with the combined
output.
I also attached a modified version using :results raw :wrap latex. I
*think* this should work, but the wrapping isn't correct. It should be
#+begin_export latex vs. #+begin_latex. I may start another thread for
this, as this is new to the current version of Org (or at least the
git version I'm on, 8.3.4). I thought the change was earlier, but if
your :output latex creates what you have above, it must not have been.
Mine automatically produces #+begin/end_export latex, but :wrap still
uses the older syntax.
Regarding the error itself, definitely seems like a bug, as you can
still see the xtable() output in the R buffer; it's just not getting
picked up by babel. Hopefully someone more knowledgeable sees this and
can comment. My contribution is just a workaround! In the end, with a
couple adjustments (footnoted), they all seem to produce the same.
Best regards,
John
[-- Attachment #2: xtable-test.org --]
[-- Type: application/octet-stream, Size: 2325 bytes --]
#+latex_header: \usepackage{booktabs}
#+options: toc:nil
* original
#+name: origy
#+BEGIN_SRC R :exports both :results replace output latex :eval no
library(xtable)
print(xtable(matrix(c(1,2,3), nrow=1)),
only.contents=TRUE, include.rownames=FALSE,
include.colnames=FALSE,
comment=FALSE, hline.after=NULL)
#+END_SRC
I took the liberty of adding =\begin/end{tabular}= below; this is the raw output from the above:
#+begin_example
#+RESULTS: orig
#+BEGIN_EXPORT latex
1.00 & 2.00 & 3.00 \\
#+END_EXPORT
#+end_example
* ascii
#+name: test
#+BEGIN_SRC R :session r :exports both :results output wrap :eval export :eval no
## use the git version as CTAN's has an error with the row/colnames options
## link: https://github.com/eusebe/ascii/issues/17
## uncomment to install via github
## install.packages("devtools")
## library(devtools)
## devtools::install_github("eusebe/ascii")
library(ascii)
options(asciiType = "org")
ascii(matrix(c(1,2,3), nrow=1))
#+END_SRC
* alternate (=:results raw :wrap latex=)
#+name: alty
#+BEGIN_SRC R :session r :exports both :results raw :wrap latex :eval no
library(xtable)
print(xtable(matrix(c(1,2,3), nrow=1)),
only.contents=TRUE, include.rownames=FALSE,
include.colnames=FALSE,
comment=FALSE, hline.after=NULL)
#+END_SRC
* comparison
What you wanted:[fn:2]
#+begin_center
#+RESULTS: orig
#+BEGIN_EXPORT latex
\begin{tabular}{lll}
1.00 & 2.00 & 3.00 \\
\end{tabular}
#+END_EXPORT
#+end_center
The ascii way:[fn:1]
#+RESULTS: test
:RESULTS:
#+attr_latex: :booktabs nil
| 1.00 | 2.00 | 3.00 |
:END:
Alternate with =:results raw :wrap latex=:[fn:3]
#+begin_center
#+RESULTS: alt
#+BEGIN_EXPORT latex
\begin{tabular}{lll}
1.00 & 2.00 & 3.00 \\
\end{tabular}
#+END_EXPORT
#+end_center
* Footnotes
[fn:3] had to add =#+begin/end_center=, correct =#+begin/end_latex= to =#+begin/end_export latex=,
and add the =\begin/end{tabular}= lines.
[fn:2] I wrapped with =#+begin/end_center= since I'm guessing the =:RESULTS:= wrap on the
ascii output centers by default. Just wanted to show them with corresponding options right
next to eachother.
[fn:1] I had to insert the =#+attr_latex= line above the results since I have the
=booktabs= package active by default and didn't want to change my config just for this exercise.
[-- Attachment #3: xtable-test.pdf --]
[-- Type: application/pdf, Size: 181442 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-03-16 17:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-10 19:11 No results when combining :session *R* with print.xtable Stephan Lindner
2016-03-16 17:56 ` John Hendy
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.