all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Preventing RESULTS from being formatted as org table [ob-awk]
@ 2016-06-12  6:46 Kaushal Modi
  2016-06-12  6:59 ` Kaushal Modi
  0 siblings, 1 reply; 9+ messages in thread
From: Kaushal Modi @ 2016-06-12  6:46 UTC (permalink / raw)
  To: emacs-org list, eschulte

[-- Attachment #1: Type: text/plain, Size: 1057 bytes --]

Hi,

I am running the latest builds of emacs-25 branch and org master branch.

I used ob-awk for the first time today and was surprised to see that the
#+RESULTS: were displayed as org tables. I do not know if that is due to
ob-awk or ob-core and so am posting it here.

Here is the minimum working example:

(1) Launch emacs -Q
(2) Create a test.txt file with the below contents (without the ===== lines
of course):

===== test.txt =====
emacs    25.0.95
org-mode 8.3.4
=====

(3) Eval (require 'ob-awk)
(4) Create this test.org file

===== test.org =====
#+BEGIN_SRC awk :in-file test.txt :exports both
{ print "My", $1, "version is", $2, "."}
#+END_SRC
=====

(5) Now with point in that src block, hit C-c C-c, answer "yes" to the
babel eval query, and you will get the below result!

#+RESULTS:
| My | emacs    | version | is | 25.0.95 | . |
| My | org-mode | version | is |   8.3.4 | . |

So how can I generate the result as one would normally see by running awk
in the terminal, without the additional org-table pipe characters?
-- 

-- 
Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 1725 bytes --]

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

* Re: Preventing RESULTS from being formatted as org table [ob-awk]
  2016-06-12  6:46 Preventing RESULTS from being formatted as org table [ob-awk] Kaushal Modi
@ 2016-06-12  6:59 ` Kaushal Modi
  2016-06-12  7:05   ` Kaushal Modi
  0 siblings, 1 reply; 9+ messages in thread
From: Kaushal Modi @ 2016-06-12  6:59 UTC (permalink / raw)
  To: emacs-org list, eschulte

[-- Attachment #1: Type: text/plain, Size: 1281 bytes --]

Bummer, found it; needed " :results raw" header arg

On Sun, Jun 12, 2016 at 2:46 AM Kaushal Modi <kaushal.modi@gmail.com> wrote:

> Hi,
>
> I am running the latest builds of emacs-25 branch and org master branch.
>
> I used ob-awk for the first time today and was surprised to see that the
> #+RESULTS: were displayed as org tables. I do not know if that is due to
> ob-awk or ob-core and so am posting it here.
>
> Here is the minimum working example:
>
> (1) Launch emacs -Q
> (2) Create a test.txt file with the below contents (without the =====
> lines of course):
>
> ===== test.txt =====
> emacs    25.0.95
> org-mode 8.3.4
> =====
>
> (3) Eval (require 'ob-awk)
> (4) Create this test.org file
>
> ===== test.org =====
> #+BEGIN_SRC awk :in-file test.txt :exports both
> { print "My", $1, "version is", $2, "."}
> #+END_SRC
> =====
>
> (5) Now with point in that src block, hit C-c C-c, answer "yes" to the
> babel eval query, and you will get the below result!
>
> #+RESULTS:
> | My | emacs    | version | is | 25.0.95 | . |
> | My | org-mode | version | is |   8.3.4 | . |
>
> So how can I generate the result as one would normally see by running awk
> in the terminal, without the additional org-table pipe characters?
> --
>
> --
> Kaushal Modi
>
-- 

-- 
Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 2253 bytes --]

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

* Re: Preventing RESULTS from being formatted as org table [ob-awk]
  2016-06-12  6:59 ` Kaushal Modi
@ 2016-06-12  7:05   ` Kaushal Modi
  2016-06-12 16:30     ` Kaushal Modi
  0 siblings, 1 reply; 9+ messages in thread
From: Kaushal Modi @ 2016-06-12  7:05 UTC (permalink / raw)
  To: emacs-org list, eschulte

[-- Attachment #1: Type: text/plain, Size: 1471 bytes --]

Correction: ":results verbatim"

On Sun, Jun 12, 2016 at 2:59 AM Kaushal Modi <kaushal.modi@gmail.com> wrote:

> Bummer, found it; needed " :results raw" header arg
>
> On Sun, Jun 12, 2016 at 2:46 AM Kaushal Modi <kaushal.modi@gmail.com>
> wrote:
>
>> Hi,
>>
>> I am running the latest builds of emacs-25 branch and org master branch.
>>
>> I used ob-awk for the first time today and was surprised to see that the
>> #+RESULTS: were displayed as org tables. I do not know if that is due to
>> ob-awk or ob-core and so am posting it here.
>>
>> Here is the minimum working example:
>>
>> (1) Launch emacs -Q
>> (2) Create a test.txt file with the below contents (without the =====
>> lines of course):
>>
>> ===== test.txt =====
>> emacs    25.0.95
>> org-mode 8.3.4
>> =====
>>
>> (3) Eval (require 'ob-awk)
>> (4) Create this test.org file
>>
>> ===== test.org =====
>> #+BEGIN_SRC awk :in-file test.txt :exports both
>> { print "My", $1, "version is", $2, "."}
>> #+END_SRC
>> =====
>>
>> (5) Now with point in that src block, hit C-c C-c, answer "yes" to the
>> babel eval query, and you will get the below result!
>>
>> #+RESULTS:
>> | My | emacs    | version | is | 25.0.95 | . |
>> | My | org-mode | version | is |   8.3.4 | . |
>>
>> So how can I generate the result as one would normally see by running awk
>> in the terminal, without the additional org-table pipe characters?
>> --
>>
>> --
>> Kaushal Modi
>>
> --
>
> --
> Kaushal Modi
>
-- 

-- 
Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 2744 bytes --]

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

* Re: Preventing RESULTS from being formatted as org table [ob-awk]
  2016-06-12  7:05   ` Kaushal Modi
@ 2016-06-12 16:30     ` Kaushal Modi
  2016-06-12 18:22       ` Thomas S. Dye
  0 siblings, 1 reply; 9+ messages in thread
From: Kaushal Modi @ 2016-06-12 16:30 UTC (permalink / raw)
  To: emacs-org list, eschulte

[-- Attachment #1: Type: text/plain, Size: 303 bytes --]

Hi all,

I learnt that I need to have ":results verbatim" as a header argument for
awk source blocks. But I don't understand why I need that in the first
place.

The default value of :results is replace. Then why is it converting the awk
results to org tables?

Thanks.

Kaushal

> --

-- 
Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 708 bytes --]

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

* Re: Preventing RESULTS from being formatted as org table [ob-awk]
  2016-06-12 16:30     ` Kaushal Modi
@ 2016-06-12 18:22       ` Thomas S. Dye
  2016-06-12 18:41         ` Kaushal Modi
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas S. Dye @ 2016-06-12 18:22 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: emacs-org list, eschulte

Aloha Kaushal,

Kaushal Modi writes:

> Hi all,
>
> I learnt that I need to have ":results verbatim" as a header argument for awk
> source blocks. But I don't understand why I need that in the first place.
>
> The default value of :results is replace. Then why is it converting the awk
> results to org tables?

There are four classes of :results header arguments.  :results replace
refers to how the results are handled.  :results verbatim refers to the
type of result returned.

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: Preventing RESULTS from being formatted as org table [ob-awk]
  2016-06-12 18:22       ` Thomas S. Dye
@ 2016-06-12 18:41         ` Kaushal Modi
  2016-06-12 19:29           ` Thomas S. Dye
  0 siblings, 1 reply; 9+ messages in thread
From: Kaushal Modi @ 2016-06-12 18:41 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: emacs-org list, eschulte

[-- Attachment #1: Type: text/plain, Size: 729 bytes --]

On Sun, Jun 12, 2016 at 2:22 PM Thomas S. Dye <tsd@tsdye.com> wrote:

> Aloha Kaushal,
>
> There are four classes of :results header arguments.  :results replace
> refers to how the results are handled.  :results verbatim refers to the
> type of result returned.
>

Hi Thomas,

Yes, I learned that from the org info manual. But it is still confusing
because in the "Type" subsection in "(org) results" info node, it says:

> The following options are mutually exclusive and specify what type of
results the code block will return.  By default, results are inserted as
either a table or scalar depending on their value.

So what determines if the results should be table formatted or kept
verbatim (scalar)?
-- 

-- 
Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 1245 bytes --]

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

* Re: Preventing RESULTS from being formatted as org table [ob-awk]
  2016-06-12 18:41         ` Kaushal Modi
@ 2016-06-12 19:29           ` Thomas S. Dye
  2016-06-12 21:02             ` Charles C. Berry
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas S. Dye @ 2016-06-12 19:29 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: emacs-org list, eschulte

Aloha Kaushal,

Kaushal Modi writes:

> On Sun, Jun 12, 2016 at 2:22 PM Thomas S. Dye <tsd@tsdye.com> wrote:
>
>     Aloha Kaushal,
>
>     There are four classes of :results header arguments. :results replace
>     refers to how the results are handled. :results verbatim refers to the
>     type of result returned.
>
>
> Hi Thomas,
>
> Yes, I learned that from the org info manual. But it is still confusing because
> in the "Type" subsection in "(org) results" info node, it says:
>
>> The following options are mutually exclusive and specify what type of
> results the code block will return. By default, results are inserted as
> either a table or scalar depending on their value.
>
> So what determines if the results should be table formatted or kept verbatim
> (scalar)?
> --

I think I'm correct to say that by default a single value result is
output as a scalar, and everything else is converted to an Org mode
table.

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: Preventing RESULTS from being formatted as org table [ob-awk]
  2016-06-12 19:29           ` Thomas S. Dye
@ 2016-06-12 21:02             ` Charles C. Berry
  2016-06-13 14:12               ` Kaushal Modi
  0 siblings, 1 reply; 9+ messages in thread
From: Charles C. Berry @ 2016-06-12 21:02 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: emacs-org list, eschulte, Kaushal Modi

On Sun, 12 Jun 2016, Thomas S. Dye wrote:

> Aloha Kaushal,
>
> Kaushal Modi writes:
>

[deleted]

>>
>> So what determines if the results should be table formatted or kept verbatim
>> (scalar)?
>> --
>
> I think I'm correct to say that by default a single value result is
> output as a scalar, and everything else is converted to an Org mode
> table.
>

TL;DR: That is almost correct. `:post' header arg gives fine control of 
formatting if needed.

`org-babel-insert-result' formats anything that isn't a string or a list 
using "%S". Then it tries hard to turn a list into a "table". Lists that 
cannot be made into tables are formatted as strings with "%s\n". However, 
various languages have their own formatting principles, so what 
`org-babel-insert-result' gets as the `result' is a bit idiosyncratic.

You can get a deeper look at the `result' by pretty printing it with the 
aid of a :post header arg. Example:


#+NAME: I-feel-pretty
#+BEGIN_SRC emacs-lisp :results pp
*this*
#+END_SRC

This elisp list is not revised:

#+BEGIN_SRC emacs-lisp :post I-feel-pretty
'(a b c (d . e))
#+END_SRC

#+RESULTS:
: (a b c
:    (d . e))


But R turns its list into an R data.frame and then into a elisp list with 
an element for each row:

#+BEGIN_SRC R :post I-feel-pretty
list(a="a",b="b", c="c", d=c("d", "e"))
#+END_SRC

#+RESULTS:
: (("a" "b" "c" "d")
:  ("a" "b" "c" "e"))

HTH,

Chuck

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

* Re: Preventing RESULTS from being formatted as org table [ob-awk]
  2016-06-12 21:02             ` Charles C. Berry
@ 2016-06-13 14:12               ` Kaushal Modi
  0 siblings, 0 replies; 9+ messages in thread
From: Kaushal Modi @ 2016-06-13 14:12 UTC (permalink / raw)
  To: Charles C. Berry, Thomas S. Dye; +Cc: emacs-org list, eschulte

[-- Attachment #1: Type: text/plain, Size: 1649 bytes --]

Hi Charles, Thomas,

Thank you for the replies. They were very useful.

I learned about :post for the first time. That minimal example worked
great. Earlier I was confused about "*this*", but then from Info node
"(org) post", I learned that it's a special variable for :post.

For now, ":results verbatim" does the job for me for awk source blocks. But
:post looks like a very powerful generic solution. With your reply, I at
least tried it out and I will keep that in mind for when I might need to
use it in future.

Kaushal

On Sun, Jun 12, 2016 at 5:02 PM Charles C. Berry <ccberry@ucsd.edu> wrote:

> TL;DR: That is almost correct. `:post' header arg gives fine control of
> formatting if needed.
>
> `org-babel-insert-result' formats anything that isn't a string or a list
> using "%S". Then it tries hard to turn a list into a "table". Lists that
> cannot be made into tables are formatted as strings with "%s\n". However,
> various languages have their own formatting principles, so what
> `org-babel-insert-result' gets as the `result' is a bit idiosyncratic.
>
> You can get a deeper look at the `result' by pretty printing it with the
> aid of a :post header arg. Example:
>
>
> #+NAME: I-feel-pretty
> #+BEGIN_SRC emacs-lisp :results pp
> *this*
> #+END_SRC
>
> This elisp list is not revised:
>
> #+BEGIN_SRC emacs-lisp :post I-feel-pretty
> '(a b c (d . e))
> #+END_SRC
>
> #+RESULTS:
> : (a b c
> :    (d . e))
>


> On Sun, 12 Jun 2016, Thomas S. Dye wrote:
>  I think I'm correct to say that by default a single value result is
>  output as a scalar, and everything else is converted to an Org mode
>  table.
>
-- 

-- 
Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 2390 bytes --]

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

end of thread, other threads:[~2016-06-13 14:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-12  6:46 Preventing RESULTS from being formatted as org table [ob-awk] Kaushal Modi
2016-06-12  6:59 ` Kaushal Modi
2016-06-12  7:05   ` Kaushal Modi
2016-06-12 16:30     ` Kaushal Modi
2016-06-12 18:22       ` Thomas S. Dye
2016-06-12 18:41         ` Kaushal Modi
2016-06-12 19:29           ` Thomas S. Dye
2016-06-12 21:02             ` Charles C. Berry
2016-06-13 14:12               ` Kaushal Modi

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.