emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org tables into R?


From: Aaron Ecay
Subject: Re: [O] org tables into R?
Date: Mon, 05 Jan 2015 23:27:38 -0500
User-agent: Notmuch/0.19+11~g3d978a0 (http://notmuchmail.org) Emacs/25.0.50.2 (x86_64-unknown-linux-gnu)

Hi Nicolas,

2015ko urtarrilak 5an, Nicolas Goaziou-ek idatzi zuen:
> 
> Hello,
> 
> Aaron Ecay <address@hidden> writes:
> 
>> Recently(-ish), Nicolas updated the org-table functions to use the
>> export framework.  One of the drawbacks of this approach (as you have
>> brought to our attention) is that export filters are invoked.  This
>> should probably be disabled.
> 
> Indeed. I removed user-defined filters and hooks. Thank you.
> 
>> Another drawback is the detection of unexpanded macros (which will be
>> triggered e.g. if a tabular babel result has macro-like {{{text}}} in
>> it).  A proof-of-concept patch for this is attached.
> 
> I don't think it needs to be fixed: macro would then be silently
> dropped, which is a step backwards. 

You are correct about the silent dropping of macro-like text.  However,
with current master that case gives an undefined macro error, which is
even worse.  Try this (in emacs -Q with org and ESS in the load-path) to
see it:

#+name: foo
#+begin_src R
  c("foo","{{{bar}}}")
#+end_src

> OTOH "ob-R.el" should consider using ":raw t" parameter for its table
> conversion function.

I think :raw is needed in ‘org-babel-insert-result’ in addition to my
previous patch.  New patch attached.
>From 4d2985ba88d2ba0c35ff715a7285469e8040d4b0 Mon Sep 17 00:00:00 2001
From: Aaron Ecay <address@hidden>
Date: Sun, 4 Jan 2015 18:14:26 -0500
Subject: [PATCH] [babel] fix macros in tabular output

* lisp/ox.el (org-export-as): Support :sloppy-macros plist entry.
* lisp/org-table.el (orgtbl-to-generic): Use it.
* lisp/ob-R.el (org-babel-R-assign-elisp):
* lisp/ob-core.el (org-babel-insert-result): Use :raw argument to
org-table conversion.
---
 lisp/ob-R.el      | 2 +-
 lisp/ob-core.el   | 2 +-
 lisp/org-table.el | 2 +-
 lisp/ox.el        | 3 ++-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 2470b4f..6f76aa5 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -239,7 +239,7 @@ This function is called by `org-babel-execute-src-block'."
             (min (if lengths (apply 'min lengths) 0)))
         ;; Ensure VALUE has an orgtbl structure (depth of at least 2).
         (unless (listp (car value)) (setq value (list value)))
-       (let ((file (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field)))
+       (let ((file (orgtbl-to-tsv value '(:raw t :fmt 
org-babel-R-quote-tsv-field)))
              (header (if (or (eq (nth 1 value) 'hline) colnames-p)
                          "TRUE" "FALSE"))
              (row-names (if rownames-p "1" "NULL")))
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 93fcb2a..9ff83f2 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2213,7 +2213,7 @@ code ---- the results are extracted in the syntax of the 
source
                                        (lambda (el) (or (listp el) (eq el 
'hline)))
                                        result)
                                       result (list result))
-                                  '(:fmt (lambda (cell) (format "%s" cell)))) 
"\n"))
+                                  '(:raw t :fmt (lambda (cell) (format "%s" 
cell)))) "\n"))
                  (goto-char beg) (when (org-at-table-p) (org-table-align)))
                 ((and (listp result) (not (funcall proper-list-p result)))
                  (insert (format "%s\n" result)))
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 6b33eda..7a53d7a 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -4834,7 +4834,7 @@ This may be either a string or a function of two 
arguments:
         (table-cell . ,(org-table--to-generic-cell params))
         ;; Section.  Return contents to avoid garbage around table.
         (section . (lambda (s c i) c))))
-      'body-only (org-combine-plists params '(:with-tables t))))))
+      'body-only (org-combine-plists params '(:with-tables t :sloppy-macros 
t))))))
 
 (defun org-table--generic-apply (value name &optional with-cons &rest args)
   (cond ((null value) nil)
diff --git a/lisp/ox.el b/lisp/ox.el
index f47baef..0fcfc04 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -2885,7 +2885,8 @@ Return code as a string."
                (cons "email" (or (plist-get info :email) ""))
                (cons "title"
                      (org-element-interpret-data (plist-get info :title))))
-         'finalize)
+         (unless (plist-get info :sloppy-macros)
+           'finalize))
         ;; Parse buffer.
         (setq tree (org-element-parse-buffer nil visible-only))
         ;; Handle left-over uninterpreted elements or objects in
-- 
2.2.1

There are several usages of orgtbl-to-* functions in babel (R, awk,
gnuplot, shell, sqlite, sql).  Org-plot also uses one.  The attached
patch adds :raw to the ob-R call, but if I understand correctly probably
all of them should add it.  Should I do that?

Thanks,

-- 
Aaron Ecay

reply via email to

[Prev in Thread] Current Thread [Next in Thread]