emacs/var/elfeed/db/data/b8/b89df3ca07c2b248a79124b4362af3ff88010d57
2022-01-03 12:49:32 -06:00

1 line
2.1 KiB
Plaintext

<!-- SC_OFF --><div class="md"><p>There is something i don&#39;t understand, a difference between behavior of org-babel and org-mode when you use org table to pass data using or not using :var.</p> <pre><code>#+NAME:mypythoncode #+begin_src python :results value raw :output :return tabulate(df, headers=df.columns, tablefmt=&#39;orgtbl&#39;) import numpy as np import pandas as pd from tabulate import tabulate df = pd.DataFrame(np.random.randint(0,10,size=(10, 4)), columns=list(&#39;ABCD&#39;)) #+end_src #+RESULTS: mypythoncode | | A | B | C | D | |---+---+---+---+---| | 0 | 0 | 9 | 6 | 0 | | 1 | 2 | 9 | 0 | 4 | | 2 | 9 | 6 | 0 | 1 | | 3 | 6 | 1 | 8 | 1 | | 4 | 4 | 2 | 1 | 4 | | 5 | 2 | 1 | 1 | 1 | | 6 | 4 | 8 | 9 | 0 | | 7 | 1 | 4 | 8 | 7 | | 8 | 9 | 3 | 2 | 5 | | 9 | 5 | 0 | 7 | 3 | #+NAME:lib-R #+HEADER: :var code=mypythoncode #+begin_src R :results output library(ggplot2) library(dplyr) library(lubridate) str(code) #+end_src #+RESULTS: lib-R : chr &quot;| | A | B | C | D |\n|----+-----+-----+-----+-----|\n| 0 | 8 | 0 | 5 | 2 |\n| 1 | 2 | &quot;| __truncated__ </code></pre> <p>As you see, the org table is not recognized as a dataframe by R. </p> <p>If i replace by a basic org table : </p> <p>&#x200B;</p> <pre><code>#+NAME: any_data | | parameter | value | |---+-----------+-------| | 0 | heats | 30 | | 1 | heats | 30 | #+NAME:lib-R #+HEADER: :var code=any_data #+begin_src R :results output library(ggplot2) library(dplyr) library(lubridate) str(code) #+end_src #+RESULTS: lib-R : &#39;data.frame&#39;: 2 obs. of 3 variables: : $ X : int 0 1 : $ parameter: chr &quot;heats&quot; &quot;heats&quot; : $ value : int 30 30 </code></pre> <p>That works...</p> <p>Any help appreciated to understand how i will resolve that ...</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/reyman64"> /u/reyman64 </a> <br/> <span><a href="https://www.reddit.com/r/emacs/comments/r5yt4a/r_talking_with_python_using_orgtable_not_work/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/emacs/comments/r5yt4a/r_talking_with_python_using_orgtable_not_work/">[comments]</a></span>