emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [ob-R] combine :post and :colnames
@ 2015-01-25 20:38 Rasmus
  2015-01-25 21:26 ` Aaron Ecay
  0 siblings, 1 reply; 5+ messages in thread
From: Rasmus @ 2015-01-25 20:38 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Am I mistaken or is it not possible to combine :colnames and :post?
Here's an example of what I have got in mind:

--8<---------------cut here---------------start------------->8---
#+NAME: identity
#+BEGIN_SRC emacs-lisp :var x="x"
x
#+END_SRC

#+BEGIN_SRC R :colnames yes :post identity(*this*)
setNames(data.frame(1:2), "foo")
#+END_SRC

#+RESULTS:
| 1 |
| 2 |

Expected result:

| foo |
|-----|
|   1 |
|   2 |
--8<---------------cut here---------------end--------------->8---

Thanks,
Rasmus

-- 
However beautiful the theory, you should occasionally look at the evidence

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

* Re: [ob-R] combine :post and :colnames
  2015-01-25 20:38 [ob-R] combine :post and :colnames Rasmus
@ 2015-01-25 21:26 ` Aaron Ecay
  2015-01-25 21:56   ` Rasmus
  0 siblings, 1 reply; 5+ messages in thread
From: Aaron Ecay @ 2015-01-25 21:26 UTC (permalink / raw)
  To: Rasmus, emacs-orgmode

Hi Rasmus,

You also have to add :colnames to the :post header:

:post identity[:colnames yes](*this*)

Another option is to add :colnames yes to the identity block itself:

#+NAME: identity
#+BEGIN_SRC emacs-lisp :var x="x" :colnames yes
  ...
#+END_SRC

-- 
Aaron Ecay

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

* Re: [ob-R] combine :post and :colnames
  2015-01-25 21:26 ` Aaron Ecay
@ 2015-01-25 21:56   ` Rasmus
  2015-01-26  8:08     ` Aaron Ecay
  0 siblings, 1 reply; 5+ messages in thread
From: Rasmus @ 2015-01-25 21:56 UTC (permalink / raw)
  To: emacs-orgmode

Aaron Ecay <aaronecay@gmail.com> writes:

> Hi Rasmus,
>
> You also have to add :colnames to the :post header:
>
> :post identity[:colnames yes](*this*)

Thanks Aaron.  That even makes sense in its own, quirky way!

Should add a note on this to the manual?  Or is it clear enough as it is?

—Rasmus

-- 
However beautiful the theory, you should occasionally look at the evidence

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

* Re: [ob-R] combine :post and :colnames
  2015-01-25 21:56   ` Rasmus
@ 2015-01-26  8:08     ` Aaron Ecay
  2015-01-26 17:31       ` Rasmus
  0 siblings, 1 reply; 5+ messages in thread
From: Aaron Ecay @ 2015-01-26  8:08 UTC (permalink / raw)
  To: Rasmus, emacs-orgmode

Hi Rasmus,

2015ko urtarrilak 25an, Rasmus-ek idatzi zuen:
> Should add a note on this to the manual?  Or is it clear enough as it
> is?

I think it would be a good idea to add a note about this in the manual.
Perhaps in the form of another example in the node for the :post header
argument (info "(org) post") which shows how to use :post to process a
tabular result.

Thanks,

-- 
Aaron Ecay

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

* Re: [ob-R] combine :post and :colnames
  2015-01-26  8:08     ` Aaron Ecay
@ 2015-01-26 17:31       ` Rasmus
  0 siblings, 0 replies; 5+ messages in thread
From: Rasmus @ 2015-01-26 17:31 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

Aaron Ecay <aaronecay@gmail.com> writes:

> 2015ko urtarrilak 25an, Rasmus-ek idatzi zuen:
>> Should add a note on this to the manual?  Or is it clear enough as it
>> is?
>
> I think it would be a good idea to add a note about this in the manual.
> Perhaps in the form of another example in the node for the :post header
> argument (info "(org) post") which shows how to use :post to process a
> tabular result.

I'm a bit busy right now, but here's a quick proposal.  If you are happy
with it, I'll push it.

—Rasmus

-- 
With monopolies the cake is a lie!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org.texi-New-example-on-babel-post-header.patch --]
[-- Type: text/x-diff, Size: 2006 bytes --]

From 721926ad040c3bf0d46660bdbf2543ea9645b3aa Mon Sep 17 00:00:00 2001
From: rasmus <rasmus@gmx.us>
Date: Mon, 26 Jan 2015 18:24:39 +0100
Subject: [PATCH] org.texi: New example on babel :post header

* org.texi (post): Clarification and new example.
---
 doc/org.texi | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 65c9309..defd015 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -15979,10 +15979,11 @@ code block execution.  When a post argument is given, the results of the code
 block will temporarily be bound to the @code{*this*} variable.  This variable
 may then be included in header argument forms such as those used in @ref{var}
 header argument specifications allowing passing of results to other code
-blocks, or direct execution via Emacs Lisp.
+blocks, or direct execution via Emacs Lisp.  Additional header arguments may
+be passed to the @code{:post}-function.
 
-The following example illustrates the usage of the @code{:post} header
-argument.
+The following two examples illustrate the usage of the @code{:post} header
+argument.  The first example shows how to attach a attribute-line via @code{:post}.
 
 @example
 #+name: attr_wrap
@@ -16007,6 +16008,31 @@ argument.
 :END:
 @end example
 
+The second examples shows how to use @code{:post} together with the
+@code{:colnames} header argument.
+@example
+#+name: round-tbl
+#+begin_src emacs-lisp :var tbl="" fmt="%.3f"
+  (mapcar (lambda (row)
+            (mapcar (lambda (cell)
+                      (if (numberp cell)
+                          (format fmt cell)
+                        cell))
+                    row))
+          tbl)
+#+end_src
+
+#+begin_src R :colnames yes :post round-tbl[:colnames yes](*this*)
+set.seed(42)
+data.frame(foo=rnorm(1))
+#+end_src
+
+#+RESULTS:
+|   foo |
+|-------|
+| 1.371 |
+@end example
+
 @node prologue
 @subsubsection @code{:prologue}
 @cindex @code{:prologue}, src header argument
-- 
2.2.2


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

end of thread, other threads:[~2015-01-26 17:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-25 20:38 [ob-R] combine :post and :colnames Rasmus
2015-01-25 21:26 ` Aaron Ecay
2015-01-25 21:56   ` Rasmus
2015-01-26  8:08     ` Aaron Ecay
2015-01-26 17:31       ` Rasmus

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