From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id WNjhM2i/SV9oVwAA0tVLHw (envelope-from ) for ; Sat, 29 Aug 2020 02:37:28 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id MI+sL2i/SV9TLAAAB5/wlQ (envelope-from ) for ; Sat, 29 Aug 2020 02:37:28 +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 E45AF940538 for ; Sat, 29 Aug 2020 02:37:27 +0000 (UTC) Received: from localhost ([::1]:55518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kBqkA-0002L8-6m for larch@yhetil.org; Fri, 28 Aug 2020 22:37:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kBqjo-0002Kz-3y for emacs-orgmode@gnu.org; Fri, 28 Aug 2020 22:37:04 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:38741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kBqjm-0000Fy-5k for emacs-orgmode@gnu.org; Fri, 28 Aug 2020 22:37:03 -0400 Received: by mail-pl1-x641.google.com with SMTP id t11so502047plr.5 for ; Fri, 28 Aug 2020 19:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=pytPaf7Zad5DLIdYNsnQQMdD5gRHwww0FSscVDzGI+M=; b=l1ovZtgSOQk2uxyxWYu58fUf6mo2ijofcDJ0inFtvBB8O/PN/axFMvdnXkppnzTZbf mruXr14CJctaq3yknaIebB2DMjl4uwZ59u98jcFU5AHUHW1EWuuJoJDBBWuS3Runuzh/ WCk0rZcihJRinEY2zeFbcHZl+SASX1GKubFxjbbUYKZC3hA6IdKGJ7A/3/sOIbQF85op m4dVRj6KxEamuDYnqRXCwyr6txADCKlCD1jENGS4Q0reSW6jB+zeviYmVV/pNN0HbsFe +4wgYYByj76GJM+qgcEmi6QBeU3z/JclLbMTpECH2gCgGjT/+x7Sfmbcg5REAGzIgsrV atGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=pytPaf7Zad5DLIdYNsnQQMdD5gRHwww0FSscVDzGI+M=; b=NNgzNMfGOGLodVOUr5Pzj25DrLsZWG62c/A04TqZbdfnuQpfIH09FN9aurIx5NsLTG LCTKDPvq8RStUjIG6X0oHRBONMywNZH6YRyko9orumcMnZt2KSd0rWhtXPQpQ/BCY50p 2clT7Zq3nLl0kJmtqpUr5xQ4uH/ZXXvwbF/kPsAKJsI5unKRUPlnSfviqGHSB1qRHiF/ br9AFHxQ/i76/BPrMY1rPDPIMxCO8sXPDM48IkS/oXoOQs7J4cIIXnHaxQPHhYIQmNio DvupXihcNg7lxPS/jVAxF5pYGk4AuYm3uz/KXy+rscHZd1OKNRQAE6l62Tk/DdEGtdXM e0Yw== X-Gm-Message-State: AOAM530Jyx4muRAlvnL9vl9kib9EwEMqa/Ua7OK6Q7JRKB+/PpGIuGOg ePwvrSEJcPfO9R79Y+7p99P7CrNeKPk= X-Google-Smtp-Source: ABdhPJxSsyZskGLlK67elBV9n4maVbMFgHJORNCIAhd8J6A166RUsiPKAIHX05VRDzThmQTLubhYXw== X-Received: by 2002:a17:90a:644b:: with SMTP id y11mr1587662pjm.13.1598668620119; Fri, 28 Aug 2020 19:37:00 -0700 (PDT) Received: from localhost (199-83-220-90.PUBLIC.monkeybrains.net. [199.83.220.90]) by smtp.gmail.com with ESMTPSA id o2sm582073pjh.4.2020.08.28.19.36.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Aug 2020 19:36:58 -0700 (PDT) From: Jack Kamm To: Dylan Schwilk , emacs-orgmode@gnu.org Subject: Re: Help debugging R source code block output problem with :session In-Reply-To: <87r1rqled0.fsf@havana> References: <87r1rqled0.fsf@havana> Date: Fri, 28 Aug 2020 19:36:58 -0700 Message-ID: <87k0xifa9h.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::641; envelope-from=jackkamm@gmail.com; helo=mail-pl1-x641.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=l1ovZtgS; 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-Spam-Score: -1.71 X-TUID: aDscKCq1Sx3D --=-=-= Content-Type: text/plain Hi Dylan, I'm able to reproduce your error. I think this same bug has been previously reported at [1]. As discussed there, the reason is that substrings ending in ">" get stripped out by org-babel-comint-with-output because it thinks they are prompts (in particular, they match comint-prompt-regexp). I'm attaching a patch to solve the issue. It replaces org-babel-comint-with-output, with an R call to capture.output. I think this approach is simpler and more robust, since it doesn't need to do any parsing to remove prompts or other unwanted outputs. I haven't committed to ob-R.el before, so thought it would be best to solicit feedback here before merging this in. Cheers, Jack [1] https://orgmode.org/list/875zgjh8wn.fsf@gmail.com/ --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ob-R-Fix-prompt-mangling-in-session-output.patch >From 1dc8e2d2cb01a4e6b82342ea8d8c965df8f5222c Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Fri, 28 Aug 2020 19:16:05 -0700 Subject: [PATCH] ob-R: Fix prompt mangling in session output * lisp/ob-R.el (org-babel-R-evaluate-session): Replace call to org-babel-comint-with-output with ess-send-to-buffer and additional wrapper R code. Fixes https://orgmode.org/list/875zgjh8wn.fsf@gmail.com/ and https://orgmode.org/list/87r1rqled0.fsf@havana/ --- lisp/ob-R.el | 79 ++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 5e9d35f58..d69cf23db 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -412,49 +412,42 @@ (defun org-babel-R-evaluate-session If RESULT-TYPE equals `output' then return standard output as a string. If RESULT-TYPE equals `value' then return the value of the last statement in BODY, as elisp." - (cl-case result-type - (value - (with-temp-buffer - (insert (org-babel-chomp body)) - (let ((ess-local-process-name - (process-name (get-buffer-process session))) - (ess-eval-visibly-p nil)) - (ess-eval-buffer nil))) - (let ((tmp-file (org-babel-temp-file "R-"))) - (org-babel-comint-eval-invisibly-and-wait-for-file - session tmp-file - (format org-babel-R-write-object-command - (if row-names-p "TRUE" "FALSE") - (if column-names-p - (if row-names-p "NA" "TRUE") - "FALSE") - ".Last.value" (org-babel-process-file-name tmp-file 'noquote))) - (org-babel-R-process-value-result - (org-babel-result-cond result-params - (with-temp-buffer - (insert-file-contents tmp-file) - (org-babel-chomp (buffer-string) "\n")) - (org-babel-import-elisp-from-file tmp-file '(16))) - column-names-p))) - (output - (mapconcat - 'org-babel-chomp - (butlast - (delq nil - (mapcar - (lambda (line) (when (> (length line) 0) line)) - (mapcar - (lambda (line) ;; cleanup extra prompts left in output - (if (string-match - "^\\([>+.]\\([ ][>.+]\\)*[ ]\\)" - (car (split-string line "\n"))) - (substring line (match-end 1)) - line)) - (org-babel-comint-with-output (session org-babel-R-eoe-output) - (insert (mapconcat 'org-babel-chomp - (list body org-babel-R-eoe-indicator) - "\n")) - (inferior-ess-send-input)))))) "\n")))) + (let ((ess-local-process-name + (process-name (get-buffer-process session))) + (ess-eval-visibly-p nil)) + (cl-case result-type + (value + (with-temp-buffer + (insert (org-babel-chomp body)) + (ess-eval-buffer nil)) + (let ((tmp-file (org-babel-temp-file "R-"))) + (org-babel-comint-eval-invisibly-and-wait-for-file + session tmp-file + (format org-babel-R-write-object-command + (if row-names-p "TRUE" "FALSE") + (if column-names-p + (if row-names-p "NA" "TRUE") + "FALSE") + ".Last.value" (org-babel-process-file-name tmp-file 'noquote))) + (org-babel-R-process-value-result + (org-babel-result-cond result-params + (with-temp-buffer + (insert-file-contents tmp-file) + (org-babel-chomp (buffer-string) "\n")) + (org-babel-import-elisp-from-file tmp-file '(16))) + column-names-p))) + (output + (let ((tmp-file (org-babel-temp-file "R-"))) + (with-temp-buffer + (insert (format "capture.output({ +%s +}, file='%s')" + body tmp-file)) + (ess-eval-buffer)) + (ess-wait-for-process) + (with-temp-buffer + (insert-file-contents tmp-file) + (buffer-string))))))) (defun org-babel-R-process-value-result (result column-names-p) "R-specific processing of return value. -- 2.28.0 --=-=-=--