From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Charles C. Berry" Subject: Re: remote plot with local output? Date: Fri, 18 Sep 2015 11:11:33 -0700 Message-ID: References: <87bnd5gho8.fsf@gentoo.org> <871te0cchw.fsf@gentoo.org> <87mvwn862v.fsf@gentoo.org> <874mis2je5.fsf@gentoo.org> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zd08h-0001Uo-HZ for emacs-orgmode@gnu.org; Fri, 18 Sep 2015 14:12:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zd08c-0006Um-FF for emacs-orgmode@gnu.org; Fri, 18 Sep 2015 14:12:03 -0400 Received: from iport-acv3-out.ucsd.edu ([132.239.0.4]:58884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zd08c-0006Lv-7C for emacs-orgmode@gnu.org; Fri, 18 Sep 2015 14:11:58 -0400 In-Reply-To: <874mis2je5.fsf@gentoo.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Benda Xu Cc: emacs-orgmode@gnu.org On Fri, 18 Sep 2015, Benda Xu wrote: > Hi, > > Benda Xu writes: > >> "Charles C. Berry" 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