From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2BVcONOpqGEbIgEAgWs5BA (envelope-from ) for ; Thu, 02 Dec 2021 12:11:15 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id APAXNNOpqGG0TwAA1q6Kng (envelope-from ) for ; Thu, 02 Dec 2021 11:11:15 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5B8E1316A for ; Thu, 2 Dec 2021 12:11:15 +0100 (CET) Received: from localhost ([::1]:45112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1msjzd-0004tM-QQ for larch@yhetil.org; Thu, 02 Dec 2021 06:11:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1msjzF-0004t9-Fo for emacs-orgmode@gnu.org; Thu, 02 Dec 2021 06:10:49 -0500 Received: from smtp-out-10.univ-rouen.fr ([193.52.155.253]:12774 helo=mailhoc.univ-rouen.fr) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1msjzB-0002RQ-6D for emacs-orgmode@gnu.org; Thu, 02 Dec 2021 06:10:49 -0500 Received: from [10.196.65.88] (ired-20-4cab-1657.univ-rouen.fr [10.196.65.88]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhoc.univ-rouen.fr (Postfix) with ESMTPSA id 850EF3FF0; Thu, 2 Dec 2021 12:10:40 +0100 (CET) Subject: Re: Org babel Python and R, table not transformed when :var is called ? From: =?UTF-8?Q?S=c3=a9bastien_Rey-Coyrehourcq?= To: emacs-orgmode@gnu.org, jeremiejuste@gmail.com References: <91cb65e0-4b2c-92ae-a69f-4d9ad8b3e1e3@univ-rouen.fr> Message-ID: <88045b81-7f7c-e591-23c9-26c682437999@univ-rouen.fr> Date: Thu, 2 Dec 2021 12:10:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <91cb65e0-4b2c-92ae-a69f-4d9ad8b3e1e3@univ-rouen.fr> Content-Type: multipart/alternative; boundary="------------ECFF4DECD68EF5014EB889E8" Content-Language: en-US Received-SPF: pass client-ip=193.52.155.253; envelope-from=sebastien.rey-coyrehourcq@univ-rouen.fr; helo=mailhoc.univ-rouen.fr X-Spam_score_int: -74 X-Spam_score: -7.5 X-Spam_bar: ------- X-Spam_report: (-7.5 / 5.0 requ) BAYES_00=-1.9, HTML_MESSAGE=0.001, NICE_REPLY_A=-3.3, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sebastien.rey-coyrehourcq@univ-rouen.fr Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1638443475; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=IA/npVXFaGOGkf52sVJoScgIrcn+QiMcM7vfQDzXYEI=; b=gShvf1WHG/+gdNnmEOFKNBMSHE1KznbK2suJnGCW3hcqMZlGe3RydGTE5w2koiL1ivkKyT f6+hc8yLZQv9b8+akTu2Q9bmVMsn3k4zC/MHyq+R28Za4qvpLBH4RVL9O90n4cGGfrjaG3 MbRYZm75il6wz2jwjQc3q1uQ4fcm+7hYpUVYFAHLJhjL6KvmectA+Qx6MQNs0at4YhAyNw TCWX2DMTJIXicilBHXEZEgSSspXBzOk9kQzPdvdswq/b1fwMPKiIpBCTYgnVwcnVyETZib JMjUJMbgL/G+HA6QD82hgQ6VJJhVyeyg/hn1jdaEXrCt0+FvQNXpdERZF6LCUw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1638443475; a=rsa-sha256; cv=none; b=uiQmLKGmn/VJWXiqzGS4wnndmV0VrG4sOhmCNLiJLAPjvcJ80wXMuffYaw0+/bRdmleZAB BnT6mn2CpvvHMuhG0m5UkrD75Vc1N+YCpJmrJAdtlmBMX8q3oaUXBSmmt9JtizYGBXob4x 3dWdW776DDHfDoBH3XwY+1vOu9FRDde1Tm9TCiX5Tg+ms91LcvuSWMlkFGVO600SrVbH6w CoTtIwQ37UCB70pKipJ8fi/1XG2m0o9u+68v0wrxB7farlElUtMcePYrw/io9kVJ59mVtj DoMjcCSZbby154fIkmor9l3SufU4EEBeCK9JPoXPDLfLqINxSMH5gcYQv5YLaQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.12 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 5B8E1316A X-Spam-Score: -2.12 X-Migadu-Scanner: scn0.migadu.com X-TUID: ndx0+rYFcWF8 This is a multi-part message in MIME format. --------------ECFF4DECD68EF5014EB889E8 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi, I found a solution using *Wrapping*, adding a #+NAME to #+RESULTS block resolve the problem. This is not defined / described into the doc, and actually i found this process a little anti-intuitive. #+RESULTS has already a name, resulting/linked from/to the execution of mypythoncode ... Best regards #+NAME: attr_wrap #+BEGIN_SRC sh :var data="" :results output   echo "#+NAME: cities"   echo "$data" #+END_SRC #+NAME:mypythoncode #+begin_src python  :results value raw :output  :post attr_wrap(data=*this*) :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 Le 01/12/2021 à 09:04, Sébastien Rey-Coyrehourcq a écrit : > > 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, > > || --------------ECFF4DECD68EF5014EB889E8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi,

I found a solution using Wrapping, adding a #+NAME to #+RESULTS block resolve the problem.

This is not defined / described into the doc, and actually i found this process a little anti-intuitive. #+RESULTS has already a name, resulting/linked from/to the execution of mypythoncode ...

Best regards


#+NAME: attr_wrap
#+BEGIN_SRC sh :var data="" :results output
  echo "#+NAME: cities"
  echo "$data"
#+END_SRC

#+NAME:mypythoncode
#+begin_src python  :results value raw :output  :post attr_wrap(data=*this*) :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

Le 01/12/2021 à 09:04, Sébastien Rey-Coyrehourcq a écrit :

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,

--------------ECFF4DECD68EF5014EB889E8--