From: "Sébastien Brisard" <sebastien.brisard@m4x.org>
To: "Charles C. Berry" <ccberry@ucsd.edu>, emacs-orgmode@gnu.org
Subject: Re: How to pass table to SRC block as strings only?
Date: Fri, 20 Jan 2017 03:34:45 +0100 [thread overview]
Message-ID: <CAGRH7Hq2FhzH9abJcFApmGKAaBLE+BeHdAFFbmPjdfLDah2DOw@mail.gmail.com> (raw)
In-Reply-To: <alpine.OSX.2.20.1701190901070.745@charles-berrys-macbook.local>
Thanks Charles for this answer. Let me state the problem more clearly.
Number-like cells *are* converted to numbers (as best illustrated by
the example below (see the use of numberp), which might incur accuracy
loss (see below, the first row has a lot of significant digits).
I am not interested in the number representation of these cells, only
the string matters for my application. Due to this accuracy loss,
converting back the number to a string is not an option for me...
Any ideas? Thanks!
Sébastien
===== begin example =====
#+NAME: table20170119
| col1 | col2 |
|------+----------------------|
| row1 | 12345678901234567890 |
| row2 | a |
| row3 | b |
| row4 | c |
#+BEGIN_SRC emacs-lisp :var table=table20170119 :colnames yes :results output
(print (map 'list (lambda (row) (nth 1 row)) table))
#+END_SRC
#+RESULTS:
:
: (1.2345678901234567e+019 "a" "b" "c")
#+BEGIN_SRC emacs-lisp :var table=table20170119 :colnames yes :results value
(map 'list (lambda (row) (numberp (nth 1 row))) table)
#+END_SRC
#+RESULTS:
| t | nil | nil | nil |
===== end example =====
2017-01-19 18:07 GMT+01:00 Charles C. Berry <ccberry@ucsd.edu>:
> On Thu, 19 Jan 2017, Sébastien Brisard wrote:
>
>> Hello all,
>> here is a MWE
>>
>> =====BEGIN MWE=====
>>
>> #+NAME: table20170119
>> | col1 | col2 |
>> |------+------------|
>> | row1 | 1234567890 |
>> | row2 | a |
>> | row3 | b |
>> | row4 | c |
>>
>> #+BEGIN_SRC emacs-lisp :var table=table20170119 :colnames yes :results
>> output
>> (print (map 'list (lambda (row) (nth 1 row)) table))
>> #+END_SRC
>>
>> #+RESULTS:
>> :
>> : (1234567890.0 "a" "b" "c")
>>
>> =====END MWE=====
>>
>> As you can see, col #1, row #1 is parsed as a float.
>
>
>
> Actually, it is not a float:
>
> #+BEGIN_SRC emacs-lisp :var table=table20170119 :colnames yes :results pp
> (number-to-string (nth 1 (car table)))
> #+END_SRC
>
> #+RESULTS:
> : "1234567890"
>
> Maybe this is what you want:
>
> #+BEGIN_SRC emacs-lisp :var table=table20170119 :colnames yes :results pp
> (map 'list (lambda (row) (format "%s" (nth 1 row))) table)
> #+END_SRC
>
> #+RESULTS:
> : ("1234567890" "a" "b" "c")
>
> HTH,
>
> Chuck
next prev parent reply other threads:[~2017-01-20 2:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-19 6:55 How to pass table to SRC block as strings only? Sébastien Brisard
2017-01-19 17:07 ` Charles C. Berry
2017-01-20 2:34 ` Sébastien Brisard [this message]
2017-01-20 3:49 ` Charles C. Berry
2017-01-21 5:30 ` Sébastien Brisard
2017-01-21 5:46 ` Sébastien Brisard
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGRH7Hq2FhzH9abJcFApmGKAaBLE+BeHdAFFbmPjdfLDah2DOw@mail.gmail.com \
--to=sebastien.brisard@m4x.org \
--cc=ccberry@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.