[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] remote plot with local output?
From: |
Benda Xu |
Subject: |
Re: [O] remote plot with local output? |
Date: |
Fri, 18 Sep 2015 17:58:58 +0900 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
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?
Yours,
Benda