emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Hendy <jw.hendy@gmail.com>
To: "Berry, Charles" <ccberry@health.ucsd.edu>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Number format for table results outut from R data.frame/tibble
Date: Sat, 21 Aug 2021 11:58:40 -0500	[thread overview]
Message-ID: <CA+M2ft_dqZz8x04Q1oJReKoUrAU=n7BY52Rg3OTSO3JAjR3M1A@mail.gmail.com> (raw)
In-Reply-To: <09213D27-4679-4C44-B512-8E257CFECA4D@health.ucsd.edu>

On Fri, Aug 6, 2021 at 2:30 PM Berry, Charles <ccberry@health.ucsd.edu> wrote:
>
> John,
>
> > On Aug 6, 2021, at 8:38 AM, John Hendy <jw.hendy@gmail.com> wrote:
> >
> > Greetings,
> >
> > I'm wondering how to align the results from the R buffer (which I
> > like) vs. the results printed by Org-mode for table results. Here's a
> > toy example:
> >
>
> `tbl_df' objects come with their own print/show method. And it does things like add color and text formats. This is nice in a terminal, but not when you want to display them in org.
>
> Turning off the color might be enough to give you a usable result:
>
> #+begin_src R :session foo :results output drawer
> library(tibble)
> options( cli.num_colors=1 )
> tmp <- tibble(x=1:5, y=x/pi)
> tmp
> #+end_src
>
> #+RESULTS:
> :results:
>
> # A tibble: 5 x 2
>       x     y
>   <int> <dbl>
> 1     1   0.3
> 2     2   0.6
> 3     3   1.
> 4     4   1.
> 5     5   2.
> :end:
>

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. I can just add my own header row and get
booktabs formatting free upon export. If I keep with :results output,
the color options trick does remove a bunch of garbage from the
output... but :results value still yields:

#+RESULTS:
| 1 | 0.318309886183791 |
| 2 | 0.636619772367581 |
| 3 | 0.954929658551372 |
| 4 |  1.27323954473516 |
| 5 |  1.59154943091895 |

I was hoping there was a way to either (a) have org post-format or (b)
take the results as printed. I'm not sure on the exact mechanism used
which creates the mismatched output in the session vs. the table. I
get that behind the scenes I still have long, irrational numbers
here... it's just that if org can print them with x decimal places, is
there some way to get Org to intercept *those* values?

John

>
> If this is not close to what you need, I suggest writing your own formatting function. If you have limited emacs-lisp skill, I suggest doing this in R.
>
> HTH,
>
> Chuck


  reply	other threads:[~2021-08-21 16:59 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 [this message]
2021-08-21 17:39     ` Berry, Charles via General discussions about Org-mode.
2021-08-21 19:55       ` Jeremie Juste

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+M2ft_dqZz8x04Q1oJReKoUrAU=n7BY52Rg3OTSO3JAjR3M1A@mail.gmail.com' \
    --to=jw.hendy@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).