emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Babel trims leading 0s for certain numbers of tables
@ 2016-07-10 12:38 Ken Mankoff
  2016-07-10 13:18 ` Eric Abrahamsen
  2016-07-10 16:50 ` Charles C. Berry
  0 siblings, 2 replies; 5+ messages in thread
From: Ken Mankoff @ 2016-07-10 12:38 UTC (permalink / raw)
  To: emacs orgmode-mailinglist


I've just discovered that when Org results are returned in a table, they are modified in that leading 0s are removed. Is this a feature? A bug? Is there a workaround for this? Leading 0s are not removed if the result is a string, but in many cases a string of numbers is still a string and should retain those 0s.

  -k.

#+BEGIN_SRC sh :results table
echo "0042"
#+END_SRC
#+RESULTS:
| 42 |

#+BEGIN_SRC sh :results table
echo "00foo"
#+END_SRC
#+RESULTS:
| 00foo |

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Babel trims leading 0s for certain numbers of tables
  2016-07-10 12:38 Babel trims leading 0s for certain numbers of tables Ken Mankoff
@ 2016-07-10 13:18 ` Eric Abrahamsen
  2016-07-10 13:35   ` Ken Mankoff
  2016-07-10 16:50 ` Charles C. Berry
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Abrahamsen @ 2016-07-10 13:18 UTC (permalink / raw)
  To: emacs-orgmode

Ken Mankoff <mankoff@gmail.com> writes:

> I've just discovered that when Org results are returned in a table,
> they are modified in that leading 0s are removed. Is this a feature? A
> bug? Is there a workaround for this? Leading 0s are not removed if the
> result is a string, but in many cases a string of numbers is still a
> string and should retain those 0s.

Maybe you can use a format specifier for that column, so the
zero-padding is retained?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Babel trims leading 0s for certain numbers of tables
  2016-07-10 13:18 ` Eric Abrahamsen
@ 2016-07-10 13:35   ` Ken Mankoff
  0 siblings, 0 replies; 5+ messages in thread
From: Ken Mankoff @ 2016-07-10 13:35 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode


On 2016-07-10 at 13:18, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
> Ken Mankoff <mankoff@gmail.com> writes:
>
>> I've just discovered that when Org results are returned in a table,
>> they are modified in that leading 0s are removed. Is this a feature? A
>> bug? Is there a workaround for this? Leading 0s are not removed if the
>> result is a string, but in many cases a string of numbers is still a
>> string and should retain those 0s.
>
> Maybe you can use a format specifier for that column, so the
> zero-padding is retained?

Maybe. Can you provide an example? Adding a #+TBLFM: after the table doesn't do it, and I'm not sure how to specify result formatting at this level of detail in babel header block arguments.

  -k.

#+BEGIN_SRC sh :results table
echo "0042"
#+END_SRC
#+RESULTS:
| 42 |
#+TBLFM: @1=@1;N

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Babel trims leading 0s for certain numbers of tables
  2016-07-10 12:38 Babel trims leading 0s for certain numbers of tables Ken Mankoff
  2016-07-10 13:18 ` Eric Abrahamsen
@ 2016-07-10 16:50 ` Charles C. Berry
  2016-07-10 17:37   ` Ken Mankoff
  1 sibling, 1 reply; 5+ messages in thread
From: Charles C. Berry @ 2016-07-10 16:50 UTC (permalink / raw)
  To: Ken Mankoff; +Cc: emacs orgmode-mailinglist

On Sun, 10 Jul 2016, Ken Mankoff wrote:

>
> I've just discovered that when Org results are returned in a table, they 
> are modified in that leading 0s are removed. Is this a feature? A bug?

Take your choice. The feature/bug happens deep down:

- org-babel-execute-src-block
   - org-babel-execute:shell
     - org-babel-import-elisp-from-file
       - org-babel-string-read
         - org-babel-read

which tries hard to convert strings to numbers.

I haven't looked hard at this, but it seems like it would take a 
significant amount of tooling to set things up to make this 
conversion optional.

> Is there a workaround for this? Leading 0s are not removed if the result 
> is a string, but in many cases a string of numbers is still a string and 
> should retain those 0s.

Lots of ways, I guess. But they would all involve either tricking 
org-babel-read and then cleaning up the mess or processing the output 
outside of org-babel-import-from-elisp.

For the latter, send the output to a file. Maybe use :file or pipe it from 
your script. Then visit the file, convert it to a table, and capture the 
result as a string. I think you can do this with a :post callout.

HTH,

Chuck

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Babel trims leading 0s for certain numbers of tables
  2016-07-10 16:50 ` Charles C. Berry
@ 2016-07-10 17:37   ` Ken Mankoff
  0 siblings, 0 replies; 5+ messages in thread
From: Ken Mankoff @ 2016-07-10 17:37 UTC (permalink / raw)
  To: Charles C. Berry; +Cc: emacs orgmode-mailinglist


On 2016-07-10 at 16:50, Charles C. Berry <ccberry@ucsd.edu> wrote:
> For the latter, send the output to a file. Maybe use :file or pipe it
> from your script.

I'm now capturing results to :file. This also make the code less dependent on Org. I still manage all the code in Org Babel blocks, but for the following block, which takes several hours to run, I cut-and-paste the code to a terminal. I can do that now that its input is from a file and not from an Org RESULTS block.

  -k.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-10 17:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-10 12:38 Babel trims leading 0s for certain numbers of tables Ken Mankoff
2016-07-10 13:18 ` Eric Abrahamsen
2016-07-10 13:35   ` Ken Mankoff
2016-07-10 16:50 ` Charles C. Berry
2016-07-10 17:37   ` Ken Mankoff

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).