emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jeremie Juste <jeremiejuste@gmail.com>
To: "Berry,
	Charles" via "General discussions about Org-mode."
	<emacs-orgmode@gnu.org>
Cc: "Berry, Charles" <ccberry@health.ucsd.edu>
Subject: Re: Number format for table results outut from R data.frame/tibble
Date: Sat, 21 Aug 2021 21:55:34 +0200	[thread overview]
Message-ID: <877dgeh8sp.fsf@gmail.com> (raw)
In-Reply-To: <CCAC7632-230E-4614-AD14-53CE590C168A@health.ucsd.edu> (Charles Berry's message of "Sat, 21 Aug 2021 17:39:00 +0000")


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	other threads:[~2021-08-21 19:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06 15:38 Number format for table results outut from R data.frame/tibble John Hendy
2021-08-06 19:30 ` Berry, Charles via General discussions about Org-mode.
2021-08-21 16:58   ` John Hendy
2021-08-21 17:39     ` Berry, Charles via General discussions about Org-mode.
2021-08-21 19:55       ` Jeremie Juste [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=877dgeh8sp.fsf@gmail.com \
    --to=jeremiejuste@gmail.com \
    --cc=ccberry@health.ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    /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).