emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] How to pass table to SRC block as strings only?


From: Sébastien Brisard
Subject: Re: [O] How to pass table to SRC block as strings only?
Date: Fri, 20 Jan 2017 03:34:45 +0100

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 <address@hidden>:
> 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




reply via email to

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