|
From: | Sébastien Rey-Coyrehourcq |
Subject: | Org babel Python and R, table not transformed when :var is called ? |
Date: | Wed, 1 Dec 2021 09:04:29 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 |
Hi there,
Perhaps it's a bug, or something i don't understand, i post on reddit (https://www.reddit.com/r/emacs/comments/r5yt4a/r_talking_with_python_using_orgtable_not_work/) to see if people on org community know the problem.
I cross post here to see if it's a know bug or somethings ?
There is something i don'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.
#+NAME:mypythoncode
#+begin_src python :results value raw :output :return tabulate(df, headers=df.columns, tablefmt='orgtbl')
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('ABCD'))
#+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 "| | A | B | C | D |\n|----+-----+-----+-----+-----|\n| 0 | 8 | 0 | 5 | 2 |\n| 1 | 2 | "| __truncated__
As you see, the org table is not recognized as a dataframe by R.
If i replace by a basic org table :
#+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 : 'data.frame': 2 obs. of 3 variables: : $ X : int 0 1 : $ parameter: chr "heats" "heats" : $ value : int 30 30
That works...
Best regards,
OpenPGP_0xD262AFCCE42732D3.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature
[Prev in Thread] | Current Thread | [Next in Thread] |