emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Hendy <jw.hendy@gmail.com>
To: Stephan Lindner <lindners@ohsu.edu>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: No results when combining :session *R* with print.xtable
Date: Wed, 16 Mar 2016 12:56:27 -0500	[thread overview]
Message-ID: <CA+M2ft84yh==Nhox15kRG8UGrMn2CyXFAhXPDNsq1fcaE9CgEA@mail.gmail.com> (raw)
In-Reply-To: <87bn6mtafl.fsf@ohsu.edu>

[-- 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 --]

      reply	other threads:[~2016-03-16 17:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-10 19:11 No results when combining :session *R* with print.xtable Stephan Lindner
2016-03-16 17:56 ` John Hendy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+M2ft84yh==Nhox15kRG8UGrMn2CyXFAhXPDNsq1fcaE9CgEA@mail.gmail.com' \
    --to=jw.hendy@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=lindners@ohsu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).