emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] remote plot with local output?


From: Charles C. Berry
Subject: Re: [O] remote plot with local output?
Date: Fri, 18 Sep 2015 11:11:33 -0700
User-agent: Alpine 2.20 (OSX 67 2015-01-07)

On Fri, 18 Sep 2015, Benda Xu wrote:

Hi,

Benda Xu <address@hidden> writes:

"Charles C. Berry" <address@hidden> writes:

Untested, but try this :

#+name: localize
#+BEGIN_SRC emacs-lisp :var file="" srcinfo=(org-babel-get-src-block-info)
   (let* ((dir (cdr (assoc :dir (nth 2 srcinfo))))
          (rfile (concat (file-name-as-directory dir) file))
          (lfile (car (last (split-string rfile ":")))))
     (copy-file rfile lfile 1)
     lfile)
#+END_SRC

then use

#+HEADER: :post localize(*this*)

in your python src block.

It successfully extracts the :dir field.  Thanks!

Python works this way.  But babel R has a completely different *this*
value.  Consider the following example:

 #+BEGIN_SRC R :results output graphics :file line.png :dir /ipmuap02:/tmp
 plot(c(1,2,3))
 #+END_SRC

 #+RESULTS:
 [[file:/scp:ipmuap02:/tmp/line.png]]

*this* equals "[[file:/scp:ipmuap02:/tmp/line.png]]", but in babel
python *this* equals "line.png".

So I come up with

 #+name: localize
 #+BEGIN_SRC emacs-lisp :var file="" srcinfo=(org-babel-get-src-block-info)
   (let ((lang (car srcinfo)))
     (cond ((string= lang "python")
            (let* ((dir (cdr (assoc :dir (nth 2 srcinfo))))
                   (rfile (concat (file-name-as-directory dir) file))
                   (lfile (car (last (split-string rfile ":")))))
              (copy-file rfile lfile 1)
              lfile))
           ((string= lang "R")
            (let* ((rfile (substring file 7 -2))
                   (lfile (car (last (split-string rfile ":")))))
              (copy-file rfile lfile 1)
              (concat "[[file:" lfile "]]")))))
 #+END_SRC

But the result is a string rather than a file link:

 #+HEADER: :post localize(*this*)
 #+BEGIN_SRC R :results output graphics :file line.png :dir /ipmuap02:/tmp
 plot(c(1,2,3))
 #+END_SRC

 #+RESULTS:
 : [[file:/tmp/line.png]]

Any hints?


Forget *this* and use the

        (cdr (assoc :file (nth 2 srcinfo))

to get the file name. That should work the same way regardless of language.

Chuck



reply via email to

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