From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id GMxOCfACSl8PXgAA0tVLHw (envelope-from ) for ; Sat, 29 Aug 2020 07:25:36 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 0D5BBfACSl85DAAA1q6Kng (envelope-from ) for ; Sat, 29 Aug 2020 07:25:36 +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 6B2AA9403D2 for ; Sat, 29 Aug 2020 07:25:35 +0000 (UTC) Received: from localhost ([::1]:41858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kBvEz-0001Gq-7t for larch@yhetil.org; Sat, 29 Aug 2020 03:25:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kBvEN-0001GV-IJ for emacs-orgmode@gnu.org; Sat, 29 Aug 2020 03:24:55 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:40975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kBvEL-0004gp-PX for emacs-orgmode@gnu.org; Sat, 29 Aug 2020 03:24:55 -0400 Received: by mail-pg1-x52b.google.com with SMTP id w186so1526283pgb.8 for ; Sat, 29 Aug 2020 00:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=ze9xHFIQJwDQ4hOF9K9UVXJVkWogKGus/zmHy5yY1Rc=; b=ATHX8QNLlpGGWQ/2+m/WU3KWxziyWW9F6+GWkusGwwzDklUdVlXnzMcfb00xalStoe A/bg2D4QM2KLKtrLuL5r13EVAoXgUrdb4e4wuVy5LCtMcho1MqHERGvmClLzfSlkCrSV Gtz4uj5VWc9CdKeT4XNkWy+U180WFbAHvYBtDHpoY/g7f/Xg8tPFaQyRDG2zD1e+HIIW wm3G1+IxXuBpwI9PiRVHFlNeIzkSE+dCV0h5oHDZrMT63695WrVrRUvAhW/nmrxNWtOV dTTREEmmBzTSMOk8OSi1JPSyYTaQ2T6GnbHEuQ73uZ51Tacwk9d401G3KMTeYr/1JbFx 7Qzw== 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:in-reply-to:references:date :message-id:mime-version; bh=ze9xHFIQJwDQ4hOF9K9UVXJVkWogKGus/zmHy5yY1Rc=; b=F8NXVLsrlvhUYyps7YHH1ehcpdoHpb+1SChwW/sTWI02msOpp1CAXZGYQmbzmpcH9X f52cvxsCIcm0Ih5NO5ddQ6humpJ5UAKt2E7Yt/y4bKnWi5moYtNPL3ANcVucYoMfFgEs LNqL8pQi2TczlT6HwrxewvaSpsgyRONzUK3nxIZQgJacj/WmAJOQMYUqOeygidE2Z2i2 Ujd2HCa2nd7o+SKXOVF4CPKRxdrigwAPIdU5ex0upNkujmTX/ZT6B6D1cvGpW3TwM652 mcu8vcvcPrF415APNcKuER4H7m/mq1K/6dLY9RR8+dKqJ0EIEu5JTB30mU+Loo44xAvb iLYg== X-Gm-Message-State: AOAM533ghN9tuBIttJ1qEUIOwB/J3V+UqKGHo1W8/df+bwGD03MsLrEw yf6sAX4sL5pJU38VQLqhceWY37Z0noc= X-Google-Smtp-Source: ABdhPJyU4iB1uXtVWYI9HOgrd7MqSAn7LGpVcX4SqqD5VQs8e7qQfdB/2rlRpqsLHnuL7EdUynefPg== X-Received: by 2002:aa7:9351:: with SMTP id 17mr2052959pfn.175.1598685892017; Sat, 29 Aug 2020 00:24:52 -0700 (PDT) Received: from localhost (199-83-220-90.PUBLIC.monkeybrains.net. [199.83.220.90]) by smtp.gmail.com with ESMTPSA id j10sm1576011pff.171.2020.08.29.00.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Aug 2020 00:24:50 -0700 (PDT) From: Jack Kamm To: Dylan Schwilk Subject: Re: Help debugging R source code block output problem with :session In-Reply-To: <87d03art6a.fsf@havana> References: <87r1rqled0.fsf@havana> <87k0xifa9h.fsf@gmail.com> <87d03art6a.fsf@havana> Date: Sat, 29 Aug 2020 00:24:50 -0700 Message-ID: <87h7slgbi5.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=jackkamm@gmail.com; helo=mail-pg1-x52b.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: , Cc: emacs-orgmode@gnu.org 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=ATHX8QNL; 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: 80cIQLUn/VdX --=-=-= Content-Type: text/plain Hi Dylan, > The patch does fix that issue -- but it introduces a different bug > for code blocks with ~:session~: the R block now only produces > output from the last statement evaluated. Of course, you're right. Good catch. Here's another attempt. It fixes the issue by modifying the R comint regular expression, requiring it to match at the beginning of the line. I think this should fix most cases, including the examples you sent. Still, it's not totally robust -- for example, it will still mangle multiline strings, if one of the lines starts with a substring that looks like a prompt. I'd be interested to hear if the attached patch works for the common cases you encounter, such as with tibbles. As an aside, I personally use an alternative implementation of ob-R sessions that doesn't suffer from this issue, and also provides some other benefits like async evaluation [1]. I'm planning to submit these changes to org-mode someday, but am not ready yet. But you may want to check it out, it was able to solve the issue in the other thread I linked as well. [1] https://github.com/jackkamm/ob-session-async --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ob-R-Fix-prompt-mangling-in-session-output.patch >From 9eaf81d708f88d06f14f9b6b9cf4182dd0fbb997 Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Sat, 29 Aug 2020 00:07:58 -0700 Subject: [PATCH] ob-R: Fix prompt mangling in session output * lisp/ob-R.el (org-babel-R-evaluate-session): Force comint prompt regexp to start at beginning of line, to prevent org-babel-comint-with-output from splitting mid-line. Fixes https://orgmode.org/list/875zgjh8wn.fsf@gmail.com/ and https://orgmode.org/list/87r1rqled0.fsf@havana/ --- lisp/ob-R.el | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 5e9d35f58..10b3b6fe3 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -450,11 +450,13 @@ (defun org-babel-R-evaluate-session (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")))) + (with-current-buffer session + (let ((comint-prompt-regexp (concat "^" comint-prompt-regexp))) + (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")))) (defun org-babel-R-process-value-result (result column-names-p) "R-specific processing of return value. -- 2.28.0 --=-=-=--