0

Expecting gnuplot to create a png on evaluating a ledgerCli plot report I get the GnuPlot error at the bottom of this post

LedgerCli

#+NAME: LedgerCli
#+BEGIN_SRC ledger :cmdline reg Assets:Cash -J
      1957/01/01  Opening Balance
           Assets:Cash  10
           Equity:OpeningBalances
      1957/01/02  Foo
           Assets:Cash  -5
           Expenses:Unknown
      1957/01/03 Bar
           Assets:Cash  -2
           Expenses:Unknown
#+END_SRC

#+RESULTS: LedgerCli
: 1957-01-01 10
: 1957-01-02 5
: 1957-01-03 3

GnuPlot

#+begin_src gnuplot :var data=LedgerCli :file gnuplot.png :exports results
  plot data u 1:2
#+end_src

#+RESULTS:
[[file:gnuplot.png]]

GnuPlot Error

    G N U P L O T
    Version 5.2 patchlevel 6    last modified 2019-01-01 

    Copyright (C) 1986-1993, 1998, 2004, 2007-2018
    Thomas Williams, Colin Kelley and many others

    gnuplot home:     http://www.gnuplot.info
    faq, bugs, etc:   type "help FAQ"
    immediate help:   type "help"  (plot window: hit 'h')

Terminal type is now 'qt'
gnuplot> cd '/home/'
gnuplot> data = "1957-01-01 10
gnuplot> 1957-01-02 5
         ^
         invalid command

gnuplot> 1957-01-03 3
         ^
         invalid command

gnuplot> "
         ^
         invalid command

gnuplot> set term png

Terminal type is now 'png'
set output "gnuplot.png"
Options are 'nocrop enhanced size 640,480 font "arial,12.0" '
gnuplot> gnuplot> plot data u 1:2
         warning: Cannot find or open file "1957-01-01 10"
         No data in plot

gnuplot> set output
gnuplot> 
gnuplot> 

From from a working org-babel gnuplot example, I noticed that gnuplot refers to data with e.g. data = "/tmp/babel-aXF0nC/gnuplot-5sxbKd. Altering the ledger cmdline to output a table with #+BEGIN_SRC ledger :cmdline reg Assets:Cash --register-format '| %D | %t |\n' doesn't change the error either

jjk
  • 705
  • 4
  • 16

1 Answers1

0

This is almost a duplicate of the working gnuplot example.

  • 1st) you need the table.
  • 2nd) use raw as output format since you format the table yourself (ob-ledger.el does not have a direct output of org-table data)

Therewith you are already in the position to give the output a name, e.g., LedgerOutput. The direct source block result LedgerCli is just a string. That is not what you want as variable header argument for the gnuplot block. You need the interpreted table data instead. You get this data if you refer to the table by its name LedgerOutput.

#+NAME: LedgerCli
#+BEGIN_SRC ledger :results raw :cmdline reg Assets:Cash --format '| %D | %t |\n'
1957/01/01  Opening Balance
           Assets:Cash  10
           Equity:OpeningBalances
1957/01/02  Foo
           Assets:Cash  -5
           Expenses:Unknown
1957/01/03 Bar
           Assets:Cash  -2
           Expenses:Unknown
#+END_SRC

#+NAME: LedgerOutput
#+RESULTS: LedgerCli
| 1957/01/01 | 10 |
| 1957/01/02 | -5 |
| 1957/01/03 | -2 |

#+begin_src gnuplot :var data=LedgerResults :file gnuplot.png :exports results
  set xdata time
  set style data linespoints
  set timefmt "%Y/%m/%d"
  plot data u 1:2
#+end_src

#+RESULTS:
[[file:gnuplot.png]]

The package ob-ledger.el is very simple. It does not transform the output of ledger into org-table data, i.e., a list of strings and numbers. For that reason the second alternative of the working gnuplot example does not work for ledger.

Therefore the results of the LegderCli block are not updated if you execute the Gnuplot block with modified Ledger-results.

If that update is important for you you can interpret the output string of the LedgerCli block by an intermediate Elisp source block as shown below.

#+NAME: LedgerCli
#+BEGIN_SRC ledger :results raw :cmdline reg Assets:Cash --format '| %D | %t |\n'
1957/01/01  Opening Balance
           Assets:Cash  10
           Equity:OpeningBalances
1957/01/02  Foo
           Assets:Cash  -5
           Expenses:Unknown
1957/01/05 Bar
           Assets:Cash  -2
           Expenses:Unknown
#+END_SRC

#+RESULTS: LedgerCli
| 1957/01/01 | 10 |
| 1957/01/02 | -5 |
| 1957/01/04 | -2 |

#+NAME: OrgTableStringInterpreter
#+BEGIN_SRC emacs-lisp :var InputString=LedgerCli
(with-temp-buffer
  (insert InputString)
  (org-element-map (org-element-parse-buffer)
      'table-row
    (lambda (row)
      (apply #'list
         (org-element-map row
         'table-cell
           (lambda (cell) (car (org-element-contents cell))))))))
#+END_SRC

#+RESULTS: OrgTableStringInterpreter
| 1957/01/01 | 10 |
| 1957/01/02 | -5 |
| 1957/01/05 | -2 |

#+begin_src gnuplot :var data=OrgTableStringInterpreter :file gnuplot.png :exports results
  set xdata time
  set style data linespoints
  set timefmt "%Y/%m/%d"
  plot data u 1:2
#+end_src

#+RESULTS:
[[file:gnuplot.png]]
Tobias
  • 32,569
  • 1
  • 34
  • 75