emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] sbe not working properly
@ 2013-04-11 14:26 Karl Voit
  2013-04-11 18:00 ` Darlan Cavalcante Moreira
  0 siblings, 1 reply; 5+ messages in thread
From: Karl Voit @ 2013-04-11 14:26 UTC (permalink / raw)
  To: emacs-orgmode

Hi!

I want to define a babel function named epoch2day which I am able to use in a
table to convert UNIX epoch times to Org-mode time stamps:

        #+NAME: epoch2day(epoch=1)
        #+BEGIN_SRC python :results output
        time = epoch
        import datetime
        strtime = str(time)
        datetimestamp = datetime.datetime.utcfromtimestamp(int(strtime[:10]))
        print datetimestamp.strftime('[%Y-%m-%d %a %H:%M:%S]')
        #+END_SRC
        
        #+RESULTS: epoch2day
        : [1970-01-01 Thu 00:00:01]

... this works so far. However, in a table I can't "overwrite" the default
value with a column value:

        |         epoch | day                       |
        |---------------+---------------------------|
        | 1262675465119 | [1970-01-01 Thu 00:00:01] |
        #+TBLFM: $2='(sbe epoch2day (epoch $1))

... but $2 should be: [2010-01-05 Tue 07:11:05]


On [1] I found another example:

        #+name: add1(x=1) :results silent
        #+begin_src python
        return x + 1
        #+end_src
        
        #+RESULTS: add1
        : 2
        
        | foo | bar | 3 | 2 |
        #+TBLFM: @1$4='(sbe add1 (x $3))
        
        #+CALL: add1(x=2)
        
        #+RESULTS: add1(x=2)
        : 2

So this simple example does not work either at my side[2].


What is my error? Or did I found a bug?

Thanks!


  1. http://stackoverflow.com/questions/9595310/org-babel-sbe-syntax
  2. Org-mode 1af215bb4668bf3e778175e68fcaf from git
-- 
mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
       > get Memacs from https://github.com/novoid/Memacs <

https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github

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

* Re: [babel] sbe not working properly
  2013-04-11 14:26 [babel] sbe not working properly Karl Voit
@ 2013-04-11 18:00 ` Darlan Cavalcante Moreira
  2013-04-11 19:15   ` Christian Moe
  0 siblings, 1 reply; 5+ messages in thread
From: Darlan Cavalcante Moreira @ 2013-04-11 18:00 UTC (permalink / raw)
  To: news1142; +Cc: emacs-orgmode


I have my own difficulties using sbe and decided to try your example.

I even created the shell babel block below which does the same think as the
python code

        #+NAME: epoch2dayshell(epoch=1)
        #+begin_src sh
        echo `date --d @$epoch -u +"[%F %a %T]"`
        #+end_src

but I got the same result. Actually, I realize a small detail.

In your example, when you evaluated the table formula you got as result the
1970 date. However, this does not mean that your python code was
executed. You got that answer because you have evaluated the python code
previously with the default argument (equal to 1) and thus you had

        #+RESULTS: epoch2day
        : [1970-01-01 Thu 00:00:01]

in your file. If you erase the #+RESULTS and reevaluate the table you will
get an ERROR. That indicates that sbe is not calling the babel block as I
(and probably you too) was expecting.

However, looking at sbe's documentation I can't see anything wrong with the
formula you wrote. I'm still confused on how to correctly use sbe.

--
Darlan

At Thu, 11 Apr 2013 16:26:12 +0200,
Karl Voit wrote:
> 
> Hi!
> 
> I want to define a babel function named epoch2day which I am able to use in a
> table to convert UNIX epoch times to Org-mode time stamps:
> 
>         #+NAME: epoch2day(epoch=1)
>         #+BEGIN_SRC python :results output
>         time = epoch
>         import datetime
>         strtime = str(time)
>         datetimestamp = datetime.datetime.utcfromtimestamp(int(strtime[:10]))
>         print datetimestamp.strftime('[%Y-%m-%d %a %H:%M:%S]')
>         #+END_SRC
>         
>         #+RESULTS: epoch2day
>         : [1970-01-01 Thu 00:00:01]
> 
> ... this works so far. However, in a table I can't "overwrite" the default
> value with a column value:
> 
>         |         epoch | day                       |
>         |---------------+---------------------------|
>         | 1262675465119 | [1970-01-01 Thu 00:00:01] |
>         #+TBLFM: $2='(sbe epoch2day (epoch $1))
> 
> ... but $2 should be: [2010-01-05 Tue 07:11:05]
> 
> 
> On [1] I found another example:
> 
>         #+name: add1(x=1) :results silent
>         #+begin_src python
>         return x + 1
>         #+end_src
>         
>         #+RESULTS: add1
>         : 2
>         
>         | foo | bar | 3 | 2 |
>         #+TBLFM: @1$4='(sbe add1 (x $3))
>         
>         #+CALL: add1(x=2)
>         
>         #+RESULTS: add1(x=2)
>         : 2
> 
> So this simple example does not work either at my side[2].
> 
> 
> What is my error? Or did I found a bug?
> 
> Thanks!
> 
> 
>   1. http://stackoverflow.com/questions/9595310/org-babel-sbe-syntax
>   2. Org-mode 1af215bb4668bf3e778175e68fcaf from git
> -- 
> mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
>        > get Memacs from https://github.com/novoid/Memacs <
> 
> https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github
> 
> 

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

* Re: [babel] sbe not working properly
  2013-04-11 18:00 ` Darlan Cavalcante Moreira
@ 2013-04-11 19:15   ` Christian Moe
  2013-04-12 22:22     ` Eric Schulte
  2013-04-13  8:01     ` [babel] sbe not working properly (resolved) Karl Voit
  0 siblings, 2 replies; 5+ messages in thread
From: Christian Moe @ 2013-04-11 19:15 UTC (permalink / raw)
  To: Darlan Cavalcante Moreira; +Cc: news1142, emacs-orgmode


Hi,

I cannot replicate Karl's problem. I copied the code examples, and got
the right results on Org 8.0-pre (pulled this morning).

I did have to make one change -- Babel wouldn't recognize the variables
until I passed them with :var rather than in parens after the codeblock
name. (I saw there was some discussion on dropping the latter syntax;
whoa -- has it already happened?) But that much was clear from the error
messages I got, so Karl's problem must be something different.

Yours,
Christian

Darlan Cavalcante Moreira writes:

> I have my own difficulties using sbe and decided to try your example.
>
> I even created the shell babel block below which does the same think as the
> python code
>
>         #+NAME: epoch2dayshell(epoch=1)
>         #+begin_src sh
>         echo `date --d @$epoch -u +"[%F %a %T]"`
>         #+end_src
>
> but I got the same result. Actually, I realize a small detail.
>
> In your example, when you evaluated the table formula you got as result the
> 1970 date. However, this does not mean that your python code was
> executed. You got that answer because you have evaluated the python code
> previously with the default argument (equal to 1) and thus you had
>
>         #+RESULTS: epoch2day
>         : [1970-01-01 Thu 00:00:01]
>
> in your file. If you erase the #+RESULTS and reevaluate the table you will
> get an ERROR. That indicates that sbe is not calling the babel block as I
> (and probably you too) was expecting.
>
> However, looking at sbe's documentation I can't see anything wrong with the
> formula you wrote. I'm still confused on how to correctly use sbe.
>
> --
> Darlan
>
> At Thu, 11 Apr 2013 16:26:12 +0200,
> Karl Voit wrote:
>> 
>> Hi!
>> 
>> I want to define a babel function named epoch2day which I am able to use in a
>> table to convert UNIX epoch times to Org-mode time stamps:
>> 
>>         #+NAME: epoch2day(epoch=1)
>>         #+BEGIN_SRC python :results output
>>         time = epoch
>>         import datetime
>>         strtime = str(time)
>>         datetimestamp = datetime.datetime.utcfromtimestamp(int(strtime[:10]))
>>         print datetimestamp.strftime('[%Y-%m-%d %a %H:%M:%S]')
>>         #+END_SRC
>>         
>>         #+RESULTS: epoch2day
>>         : [1970-01-01 Thu 00:00:01]
>> 
>> ... this works so far. However, in a table I can't "overwrite" the default
>> value with a column value:
>> 
>>         |         epoch | day                       |
>>         |---------------+---------------------------|
>>         | 1262675465119 | [1970-01-01 Thu 00:00:01] |
>>         #+TBLFM: $2='(sbe epoch2day (epoch $1))
>> 
>> ... but $2 should be: [2010-01-05 Tue 07:11:05]
>> 
>> 
>> On [1] I found another example:
>> 
>>         #+name: add1(x=1) :results silent
>>         #+begin_src python
>>         return x + 1
>>         #+end_src
>>         
>>         #+RESULTS: add1
>>         : 2
>>         
>>         | foo | bar | 3 | 2 |
>>         #+TBLFM: @1$4='(sbe add1 (x $3))
>>         
>>         #+CALL: add1(x=2)
>>         
>>         #+RESULTS: add1(x=2)
>>         : 2
>> 
>> So this simple example does not work either at my side[2].
>> 
>> 
>> What is my error? Or did I found a bug?
>> 
>> Thanks!
>> 
>> 
>>   1. http://stackoverflow.com/questions/9595310/org-babel-sbe-syntax
>>   2. Org-mode 1af215bb4668bf3e778175e68fcaf from git
>> -- 
>> mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
>>        > get Memacs from https://github.com/novoid/Memacs <
>> 
>> https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github
>> 
>> 

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

* Re: [babel] sbe not working properly
  2013-04-11 19:15   ` Christian Moe
@ 2013-04-12 22:22     ` Eric Schulte
  2013-04-13  8:01     ` [babel] sbe not working properly (resolved) Karl Voit
  1 sibling, 0 replies; 5+ messages in thread
From: Eric Schulte @ 2013-04-12 22:22 UTC (permalink / raw)
  To: Christian Moe; +Cc: news1142, emacs-orgmode

Christian Moe <mail@christianmoe.com> writes:

> Hi,
>
> I cannot replicate Karl's problem. I copied the code examples, and got
> the right results on Org 8.0-pre (pulled this morning).
>
> I did have to make one change -- Babel wouldn't recognize the variables
> until I passed them with :var rather than in parens after the codeblock
> name. (I saw there was some discussion on dropping the latter syntax;
> whoa -- has it already happened?)

Yes, this syntax has been removed.

> But that much was clear from the error messages I got, so Karl's
> problem must be something different.
>
> Yours,
> Christian
>
> Darlan Cavalcante Moreira writes:
>
>> I have my own difficulties using sbe and decided to try your example.
>>
>> I even created the shell babel block below which does the same think as the
>> python code
>>
>>         #+NAME: epoch2dayshell(epoch=1)
>>         #+begin_src sh
>>         echo `date --d @$epoch -u +"[%F %a %T]"`
>>         #+end_src
>>
>> but I got the same result. Actually, I realize a small detail.
>>
>> In your example, when you evaluated the table formula you got as result the
>> 1970 date. However, this does not mean that your python code was
>> executed. You got that answer because you have evaluated the python code
>> previously with the default argument (equal to 1) and thus you had
>>
>>         #+RESULTS: epoch2day
>>         : [1970-01-01 Thu 00:00:01]
>>
>> in your file. If you erase the #+RESULTS and reevaluate the table you will
>> get an ERROR. That indicates that sbe is not calling the babel block as I
>> (and probably you too) was expecting.
>>
>> However, looking at sbe's documentation I can't see anything wrong with the
>> formula you wrote. I'm still confused on how to correctly use sbe.
>>
>> --
>> Darlan
>>
>> At Thu, 11 Apr 2013 16:26:12 +0200,
>> Karl Voit wrote:
>>> 
>>> Hi!
>>> 
>>> I want to define a babel function named epoch2day which I am able to use in a
>>> table to convert UNIX epoch times to Org-mode time stamps:
>>> 
>>>         #+NAME: epoch2day(epoch=1)
>>>         #+BEGIN_SRC python :results output
>>>         time = epoch
>>>         import datetime
>>>         strtime = str(time)
>>>         datetimestamp = datetime.datetime.utcfromtimestamp(int(strtime[:10]))
>>>         print datetimestamp.strftime('[%Y-%m-%d %a %H:%M:%S]')
>>>         #+END_SRC
>>>         
>>>         #+RESULTS: epoch2day
>>>         : [1970-01-01 Thu 00:00:01]
>>> 
>>> ... this works so far. However, in a table I can't "overwrite" the default
>>> value with a column value:
>>> 
>>>         |         epoch | day                       |
>>>         |---------------+---------------------------|
>>>         | 1262675465119 | [1970-01-01 Thu 00:00:01] |
>>>         #+TBLFM: $2='(sbe epoch2day (epoch $1))
>>> 
>>> ... but $2 should be: [2010-01-05 Tue 07:11:05]
>>> 
>>> 
>>> On [1] I found another example:
>>> 
>>>         #+name: add1(x=1) :results silent
>>>         #+begin_src python
>>>         return x + 1
>>>         #+end_src
>>>         
>>>         #+RESULTS: add1
>>>         : 2
>>>         
>>>         | foo | bar | 3 | 2 |
>>>         #+TBLFM: @1$4='(sbe add1 (x $3))
>>>         
>>>         #+CALL: add1(x=2)
>>>         
>>>         #+RESULTS: add1(x=2)
>>>         : 2
>>> 
>>> So this simple example does not work either at my side[2].
>>> 
>>> 
>>> What is my error? Or did I found a bug?
>>> 
>>> Thanks!
>>> 
>>> 
>>>   1. http://stackoverflow.com/questions/9595310/org-babel-sbe-syntax
>>>   2. Org-mode 1af215bb4668bf3e778175e68fcaf from git
>>> -- 
>>> mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
>>>        > get Memacs from https://github.com/novoid/Memacs <
>>> 
>>> https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github
>>> 
>>> 
>
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

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

* Re: [babel] sbe not working properly (resolved)
  2013-04-11 19:15   ` Christian Moe
  2013-04-12 22:22     ` Eric Schulte
@ 2013-04-13  8:01     ` Karl Voit
  1 sibling, 0 replies; 5+ messages in thread
From: Karl Voit @ 2013-04-13  8:01 UTC (permalink / raw)
  To: emacs-orgmode

* Christian Moe <mail@christianmoe.com> wrote:
>
> Hi,

Hi!

> I cannot replicate Karl's problem. I copied the code examples, and got
> the right results on Org 8.0-pre (pulled this morning).
>
> I did have to make one change -- Babel wouldn't recognize the variables
> until I passed them with :var rather than in parens after the codeblock
> name. (I saw there was some discussion on dropping the latter syntax;
> whoa -- has it already happened?) 

I can confirm that using the :var syntax, it is working properly:

    #+NAME: epoch2day
    #+BEGIN_SRC python :results output :var epoch=1262675465119
    time = epoch
    import datetime
    strtime = str(time)
    datetimestamp = datetime.datetime.utcfromtimestamp(int(strtime[:10]))
    print datetimestamp.strftime('[%Y-%m-%d %a %H:%M:%S]')
    #+END_SRC
    
    #+RESULTS: epoch2day
    : [2010-01-05 Tue 07:11:05]
    
    |         epoch | day                       |
    |---------------+---------------------------|
    | 1262675465119 | [2010-01-05 Tue 07:11:05] |
    |        123456 | [1970-01-02 Fri 10:17:36] |
    |      99998754 | [1973-03-03 Sat 09:25:54] |
    #+TBLFM: $2='(sbe epoch2day (epoch $1))

... works (and enriches my Org-mode capabilities enourmously! :-).

    #+name: add1
    #+begin_src python  :results silent :var x=1
    return x + 1
    #+end_src
    
    #+RESULTS: add1
    : 2
    
    | foo | bar | 3 | 4 |
    #+TBLFM: @1$4='(sbe add1 (x $3))

... does work as well.

Thanks for pointing me to the change of syntax.

-- 
mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
       > get Memacs from https://github.com/novoid/Memacs <

https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github

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

end of thread, other threads:[~2013-04-13  8:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-11 14:26 [babel] sbe not working properly Karl Voit
2013-04-11 18:00 ` Darlan Cavalcante Moreira
2013-04-11 19:15   ` Christian Moe
2013-04-12 22:22     ` Eric Schulte
2013-04-13  8:01     ` [babel] sbe not working properly (resolved) Karl Voit

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