emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Number format for table results outut from R data.frame/tibble


From: Berry, Charles
Subject: Re: Number format for table results outut from R data.frame/tibble
Date: Sat, 21 Aug 2021 17:39:00 +0000


> On Aug 21, 2021, at 9:58 AM, John Hendy <jw.hendy@gmail.com> wrote:
> 
> 
> Interesting, and thanks for taking a look. I don't think I specified
> sufficiently that I'm actually aiming for latex/pdf output and
> therefore want the org table. 

John,

If you want a latex export, you should use one of the many R packages[1] that 
format R objects for latex output.

For example:

#+begin_src R :session foo :results output latex
library(tibble)
library(xtable)
tmp <- tibble(x=1:5, y=x/pi)
xtable(tmp)
#+end_src

#+RESULTS:
#+begin_export latex

% latex table generated in R 4.1.0 by xtable 1.8-4 package
% Sat Aug 21 10:23:18 2021
\begin{table}[ht]
\centering
\begin{tabular}{rrr}
  \hline
 & x & y \\ 
  \hline
1 &   1 & 0.32 \\ 
  2 &   2 & 0.64 \\ 
  3 &   3 & 0.95 \\ 
  4 &   4 & 1.27 \\ 
  5 &   5 & 1.59 \\ 
   \hline
\end{tabular}
\end{table}
#+end_export

The xtable() and its print method have loads of options for formatting, setting 
environments and labels, and adding captions.

If you insist on doing this in org without the assistance of an R package, you 
will need to use a `:post' header argument.  If you have solid elisp skills, 
this is a viable option.

HTH,
Chuck

[1] One list of such is at: 
https://stackoverflow.com/questions/5465314/tools-for-making-latex-tables-in-r



reply via email to

[Prev in Thread] Current Thread [Next in Thread]