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: Jeremie Juste
Subject: Re: Number format for table results outut from R data.frame/tibble
Date: Sat, 21 Aug 2021 21:55:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hello, John

For my workflow, I generally use the minimum from xtable and do the
formatting in org-mode using the :post parameter to call another lisp code
block.


That said, as Chuck said, you can go a long way with xtable. In my
attic, I found the following code where I take only the core data from
xtable and do formatting in org-mode. This code may be a little
extravagant on the latex side but, it shows the possibilities.

HTH,

Jeremie

#+LATEX_HEADER: \usepackage{booktabs}
#+LATEX_HEADER: \usepackage{array}
#+LATEX_HEADER: \usepackage{setspace}
#+LATEX_HEADER: \usepackage{dcolumn}
#+LATEX_HEADER: \usepackage{array}
#+LATEX_HEADER: \usepackage{setspace}
#+LATEX_HEADER:\usepackage{longtable,tabularx,ltablex}
#+LATEX_HEADER:\usepackage{siunitx}
#+LATEX_HEADER:\usepackage[flushleft]{threeparttablex}


#+Name: add-table-env
#+BEGIN_SRC emacs-lisp :var  table="TABLE" notes="NOTES" caption="CAPTION" 
:results silent :exports none
(replace-regexp-in-string 
"\\\\begin{tabular}.*\\S.*\\toprule\\|\\\\end{tabular}" "" 
(format "\\scriptsize{
\\begin{center}
\\begin{TableNotes}\\footnotesize
 \\item[\\hspace{-\\fontdimen2\\font}]   
%s
\\end{TableNotes}
\\begin{ThreePartTable}
     \\sisetup{table-format=-2.3, table-space-text-post=***, 
table-number-alignment=center}
\\keepXColumns
\\begin{tabularx}{\\textwidth}{l *{3}{D..{5.3}}}
\\caption{%s} \\\\
\\toprule
\\toprule
\\multicolumn{1}{c}{colnum 1} &\\multicolumn{1}{c}{colnum 2}   \\\\
  \\cmidrule(lr){1-1}  \\cmidrule(lr){2-2}  

%s
\\insertTableNotes
\\end{tabularx}
\\end{ThreePartTable}
\\end{center}
}
\\pagebreak
" notes caption table))
 #+END_SRC




#+begin_src R :session foo :results output latex :post add-table-env(*this*, 
"Some note", "A caption" ) :exports results
  library(tibble)
  library(xtable)
  tmp <- tibble(x=1:5, y=x/pi)
  print.xtable(xtable(tmp),
               include.colnames=FALSE,include.rownames=FALSE,floating=FALSE,
               comment = FALSE,dcolumn=TRUE,booktabs=TRUE
              ,sanitize.text.function = function(x) {
                x[x=="NA"] <-""
                x})
#+end_src




reply via email to

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