From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id uAErB96602DLPQEAgWs5BA (envelope-from ) for ; Thu, 24 Jun 2021 00:51:10 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id UNDXAt6602CeVwAA1q6Kng (envelope-from ) for ; Wed, 23 Jun 2021 22:51:10 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3EA0F1D939 for ; Thu, 24 Jun 2021 00:51:09 +0200 (CEST) Received: from localhost ([::1]:47058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwBi7-0007C3-Ll for larch@yhetil.org; Wed, 23 Jun 2021 18:51:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwBhG-0007Au-Se for emacs-orgmode@gnu.org; Wed, 23 Jun 2021 18:50:14 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:40738) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwBhA-0006hi-Pw for emacs-orgmode@gnu.org; Wed, 23 Jun 2021 18:50:14 -0400 Received: by mail-wm1-x333.google.com with SMTP id o33-20020a05600c5121b02901e360c98c08so3221038wms.5 for ; Wed, 23 Jun 2021 15:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:user-agent:mime-version; bh=nIMElNpGsPDhdnuqy+R/i99SLgavyis8bGal53k0OTw=; b=ZqdoImJAvjYX4MexZvvKtsk3WY2YEeySq9c1W+DxgPf2XF8Wl9DwCsAQR4bzttYNWl l8dijHKwFhw/FsO3AmVmoZL5fMrFcGaU8C/uWFcagtnrl736UVzrNtwS2vMKUxeBQPOp V9brdOHgTkdKdkds/qkaU066LJ4gmmXw3DSVeI/fOCjZH+h1FbIhGVvamR4C8At66rCk usqHAZTYc6lY8EpKuYxDPOp+RoinqwhuJQmnwbbmBlIOJdpJQHLzkOfAqinM0brIznRf Z6ldm4hXar8/HJEc+I7D1ujG6TzwLxb2wZwxg4QOZ4wDGhSuhczOdMy3Aoo+vtypgtQv q/fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:user-agent :mime-version; bh=nIMElNpGsPDhdnuqy+R/i99SLgavyis8bGal53k0OTw=; b=gyAZl2zZMqPMwVq8au/73uPr7FfAzJKRVgE5fwNro95J/iIhgElhe3N3ovXVApWe2o P2fQTJ2RMuaQtVW8qJEldG05uzhlFrSqtiTC3dFlLssfikCm4IfGORnRBrWUK90RGP/y dZ2Xybmae/yhzfB4FTFoBg9eBAvFxJ3nMT5b6T695wS+/1i1gKiunDAPwBOzHBeSkHWc ocu2OKt0zW1E6ImNth/n4ieB5olD1vhv91YRQnsrwR2x7QFsX6uxxnezuuUFCeDAL1F/ EmbT42gbvsb5774okrOvHczvqqp6XlMUGTC0mQuQJvzIREVvk6D2Hnq/UlRcfIrurt8L D0tQ== X-Gm-Message-State: AOAM530R9f/vT1yaG4lrSDNLiDieQFFvCYfoRN8CuWKnO0fjDk9IFjiT YB3Q3ov7oQS071lTSY8BS58= X-Google-Smtp-Source: ABdhPJzAbVgFDmUoYp+PJRIF0jZh46V/i4JROK32EmjUxBM3rN7vF3eAFV3rIk7hRtS3SL4Pu0sZWg== X-Received: by 2002:a1c:4682:: with SMTP id t124mr482050wma.161.1624488606293; Wed, 23 Jun 2021 15:50:06 -0700 (PDT) Received: from freegnu (82-64-129-7.subs.proxad.net. [82.64.129.7]) by smtp.gmail.com with ESMTPSA id x10sm1339574wru.58.2021.06.23.15.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 15:50:05 -0700 (PDT) From: Jeremie Juste To: Org Mode Subject: [PATCH] ob-R output file with graphics parameter Date: Thu, 24 Jun 2021 00:50:04 +0200 Message-ID: <8735t8nqlf.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=jeremiejuste@gmail.com; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jack Kamm , "Berry, Charles" Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1624488669; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=nIMElNpGsPDhdnuqy+R/i99SLgavyis8bGal53k0OTw=; b=Fr2vWbEIZfxE0qspR9GUYrir/5U7zailVTLVHLnRMg1YQvzfdmIHxm0Sn50LbswKzEI7K6 7eP/mk7NUswRV4HvAyX8X5ALUnRCWT+g7q40/0uWt7rgLw+qbPnTpW/ZrvPLQCF/a1GNLU z8Gl0SpP8Clf0rGaR0vitqWVIeuMK+jbPVusXNBam0OHw3QVhDz39oRPOpzbacH4/wZy/s //r2wVVAPpgBdVg8cF+zAj1K7uCa1j10G5bM4xJ97atw1UdvTlWWZByvi3sL14uSdQuaA3 PiIcVi4bdsDuDnpfXYSpue94JTkndzatPyGlD2S8eANDpfHfVZAtxMKyq1c0pQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1624488669; a=rsa-sha256; cv=none; b=dOmMC1UlmRYyFrMFE/DVXiV/KTSBpnsRrVXB7A+pd3G6t6UoDlXIfWrif0B8NmxiERYKMC jY05Nf+b1DjTtvrqw8FL+lH4A3Wx7/Mj1D6JiFvPy89v8X2glbEN66uvZQOf6Bh7yTm9y3 h0mDo5duBAmEnMRzjeVW3FyzJO/c2NTqhrlX7qwWz5sNIq/vErFPN39Np4BTZcansxjwhB HU87ivuxvnC+IBGv7w8ZSpX3BhFG5Jj+3HDJbeXems0OH3BtXIkzpN4tSEkg+I6Hpo6OkA qmOnFOVayiqX21Che26DAMCunZQ0NLM3XwSupyNJ/G5C9X+vzOVe3tOP5o2qRA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=ZqdoImJA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -3.13 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=ZqdoImJA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 3EA0F1D939 X-Spam-Score: -3.13 X-Migadu-Scanner: scn0.migadu.com X-TUID: WzcfGk/35JFS --=-=-= Content-Type: text/plain Hello, With the following patch the link to graphics output is finally back on with R source code. Note that on top of the "graphics" parameter the "file" parameter have to be used for the org-link to work out of the box. I will try to remove the need for a second "file" parameter in the future. #+begin_src R :results output graphics file :file test2.pdf :session *local* :cache no :dir "~/Documents/images" plot(rnorm(100)) #+end_src #+RESULTS: [[file:images/test2.pdf]] The link also works for R remote sessions. Comments are welcome. The next steps - Remove second the need for a second file parameter - Add tests to avoid regression - implement async in ob-R --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=ob-R-graphs.patch >From e3d37da7b643990dc70ee42528051f1323fa5cae Mon Sep 17 00:00:00 2001 From: Jeremie Juste Date: Wed, 23 Jun 2021 23:58:26 +0200 Subject: [PATCH 1/4] ob-R.el: Remove redundant argument to function * lisp/ob-R.el (org-babel-R-construct-graphics-device-call): Modify function to take only 'params' and not 'graphics-file'. The parameter graphics-file can be extracted from params. --- lisp/ob-R.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 2d9073cee..8266dc4ae 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -170,8 +170,7 @@ This function is called by `org-babel-execute-src-block'." (mapconcat 'identity (if graphics-file (append - (list (org-babel-R-construct-graphics-device-call - graphics-file params)) + (list (org-babel-R-construct-graphics-device-call params)) inside (list "},error=function(e){plot(x=-1:1, y=-1:1, type='n', xlab='', ylab='', axes=FALSE); text(x=0, y=0, labels=e$message, col='red'); paste('ERROR', e$message, sep=' : ')}); dev.off()")) inside) @@ -311,13 +310,16 @@ Each member of this list is a list with three members: 3. the name of the argument to this function which specifies the file to write to (typically \"file\" or \"filename\")") -(defun org-babel-R-construct-graphics-device-call (out-file params) +(defun org-babel-R-construct-graphics-device-call (params) "Construct the call to the graphics device." (let* ((allowed-args '(:width :height :bg :units :pointsize :antialias :quality :compression :res :type :family :title :fonts :version :paper :encoding :pagecentre :colormodel :useDingbats :horizontal)) + + (out-file (cdr (assq :file params))) + (device (file-name-extension out-file)) (device-info (or (assq (intern (concat ":" device)) org-babel-R-graphics-devices) -- 2.20.1 >From 589eab5d98a4156b46943c7201404300f0ae6ca0 Mon Sep 17 00:00:00 2001 From: Jeremie Juste Date: Thu, 24 Jun 2021 00:04:59 +0200 Subject: [PATCH 2/4] ob-R.el: New function to construct org-link * lisp/ob-R.el (org-babel-output-link-path:R): New function to contruct org-link from 'params'. --- lisp/ob-R.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 8266dc4ae..c325c9cfa 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -185,6 +185,13 @@ This function is called by `org-babel-execute-src-block'." (org-babel-pick-name (cdr (assq :rowname-names params)) rownames-p))))) (if graphics-file nil result)))) +(defun org-babel-output-link-path:R (params) + "format org-link to file from PARAMS" + + (format "[[file:%s]]" (concat (cdr (assq :dir params)) + "/" + (cdr (assq :file params))))) + (defun org-babel-prep-session:R (session params) "Prepare SESSION according to the header arguments specified in PARAMS." -- 2.20.1 >From b55148df0da94312e1a3e5709263ed9b66355384 Mon Sep 17 00:00:00 2001 From: Jeremie Juste Date: Thu, 24 Jun 2021 00:07:39 +0200 Subject: [PATCH 3/4] ob-R.el: Return link if graphics parameter is used * lisp/ob-R.el (org-babel-execute:R): Return org-link instead of nil if graphics parameter is used. --- lisp/ob-R.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index c325c9cfa..9f32db97a 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -184,7 +184,9 @@ This function is called by `org-babel-execute-src-block'." (or (equal "yes" rownames-p) (org-babel-pick-name (cdr (assq :rowname-names params)) rownames-p))))) - (if graphics-file nil result)))) + (if graphics-file (org-babel-output-link-path:R params) + result)))) + (defun org-babel-output-link-path:R (params) "format org-link to file from PARAMS" -- 2.20.1 >From 12a06671415a55c726975d6e0297a20aefbbce62 Mon Sep 17 00:00:00 2001 From: Jeremie Juste Date: Thu, 24 Jun 2021 00:11:10 +0200 Subject: [PATCH 4/4] ob-R.el: Handle graphics file path for remote R session * lisp/ob-R.el (org-babel-R-construct-graphics-device-call): If R session is remote, remove "/ssh:" part in file path before writing the graph to file on remote host. --- lisp/ob-R.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 9f32db97a..2769804a4 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -336,6 +336,11 @@ Each member of this list is a list with three members: (extra-args (cdr (assq :R-dev-args params))) filearg args) (setq device (nth 1 device-info)) (setq filearg (nth 2 device-info)) + (setq out-file-path (concat + (replace-regexp-in-string "/ssh:.*?:" "" (cdr (assq :dir params))) + "/" + out-file)) + (setq args (mapconcat (lambda (pair) (if (member (car pair) allowed-args) @@ -344,7 +349,7 @@ Each member of this list is a list with three members: (cdr pair)) "")) params "")) (format "%s(%s=\"%s\"%s%s%s); tryCatch({" - device filearg out-file args + device filearg out-file-path args (if extra-args "," "") (or extra-args "")))) (defconst org-babel-R-eoe-indicator "'org_babel_R_eoe'") -- 2.20.1 --=-=-= Content-Type: text/plain Best regards, -- Jeremie Juste --=-=-=--