From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: Re: R code block produces only partial output Date: Sat, 23 Aug 2014 04:32:03 -0400 Message-ID: <871ts7r4ho.fsf@gmail.com> References: <87iom8zd24.fsf@gmail.com> <877g2oz9gv.fsf@gmail.com> <87lhr27oap.fsf@gmail.com> <87r40uwavs.fsf@gmail.com> <8761i5kg8f.fsf@gmail.com> <87ppgcrg8n.fsf@gmail.com> <87lhr0qimr.fsf@gmail.com> <87wqa9owhv.fsf@gmail.com> <87oavkp2xa.fsf@gmail.com> <87r40f8xfo.fsf@Rainer.invalid> <87a9718hg7.fsf@gmail.com> <877g2511mx.fsf@Rainer.invalid> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XL6kB-0004fI-FT for emacs-orgmode@gnu.org; Sat, 23 Aug 2014 04:32:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XL6k2-0004JM-9V for emacs-orgmode@gnu.org; Sat, 23 Aug 2014 04:32:15 -0400 Received: from mail-qc0-x22d.google.com ([2607:f8b0:400d:c01::22d]:55120) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XL6k2-0004JG-32 for emacs-orgmode@gnu.org; Sat, 23 Aug 2014 04:32:06 -0400 Received: by mail-qc0-f173.google.com with SMTP id w7so11643703qcr.4 for ; Sat, 23 Aug 2014 01:32:05 -0700 (PDT) In-Reply-To: <877g2511mx.fsf@Rainer.invalid> 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: Achim Gratz , emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 2014ko abuztuak 19an, Achim Gratz-ek idatzi zuen: >=20 > Aaron Ecay writes: >> R is capable of installing packages to a user-specified directory, >> without requiring root or any other special privileges. So IT cannot >> literally prevent R users from installing their own packages; >=20 > They can, all they have to do is to take away the ability to connect to > the outside network and that's what is increasingly being done (for > other reasons, mind you). >=20 >> the requirement must rather come as a statement of policy. >=20 > That is another common thing, if only to shift the responsibility if the > other measures don't actually prevent that. >=20 >> I=E2=80=99d like to >> understand more about how such regimes work and how org could work >> with them, ideally from people who have direct experience with them. >=20 > Ideally, don't require the use of a non-core package. The beef with > things like CTAN, CRAN or CPAN is that they require extra maintenance > beyond the pure installation of some software and some specific > knowledge of the software in question and that's just not going to > happen in some places. >=20 >> Otherwise, it would be disappointing if the fear that an unidentifiable >> somebody somewhere might not be able to install R packages derailed the >> improvement of babel=E2=80=99s R support. >=20 > The request was to keep a fallback to core. I have no comment at this > time if it would be possible or not. Since ultimately it's the session > support of Emacs that is clunky (and that affects most other languages > as well), maybe an effort to improve that would be more generally > helpful than working around it in different ways in each language. Well, I think that it=E2=80=99s going to be difficult to make babel a better literate programming solution for R if we restrict ourselves not to use the state-of-the-art R package for low-level literate programming support. Org is full of features which one needs to install other software to use, and I=E2=80=99m comfortable with the idea that babel=E2=80= =99s R support should require the evaluate package. However, it=E2=80=99s difficu= lt to argue this point of view when no one has spoken up about their own requirements, and a spirit of conservatism in the face of vague imagined difficulties persists. The attached patch fixes the problem that touched off this thread. It=E2=80=99s only debatably nicer than the present approach, but it has the independently desirable property of segregating babel-driven output from the session buffer. It incorporates what I think is a fix for the tramp bug Charles pointed out. It=E2=80=99s as yet only lightly tested, and as always comments are welcome. --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-ob-R-overhaul-handling-of-output-results-type-in-a-s.patch Content-Transfer-Encoding: quoted-printable >From 5f3b4ec203b8bc14c3da975368481c3767ab6f02 Mon Sep 17 00:00:00 2001 From: Aaron Ecay Date: Sat, 16 Aug 2014 00:49:05 -0400 Subject: [PATCH] ob-R: overhaul handling of :output results type in a sessi= on MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * (org-babel-R-evaluate-session): Capture output using =E2=80=98ess-execute= =E2=80=99. This function dumps the output from R into a buffer; we then use some tricks to clean it of spurious text. --- lisp/ob-R.el | 63 +++++++++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 41b943c..2d8220b 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -364,9 +364,10 @@ last statement in BODY, as elisp." (output (org-babel-eval org-babel-R-command body)))) =20 (defvar ess-eval-visibly-p) +(defvar ess-execute-in-process-buffer) =20 (defun org-babel-R-evaluate-session - (session body result-type result-params column-names-p row-names-p) + (session body result-type result-params column-names-p row-names-p) "Evaluate BODY in SESSION. If RESULT-TYPE equals 'output then return standard output as a string. If RESULT-TYPE equals 'value then return the value of the @@ -396,23 +397,49 @@ last statement in BODY, as elisp." (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 - "^\\([ ]*[>+\\.][ ]?\\)+\\([[0-9]+\\|[ ]\\)" line) - (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* ((sentinel-file (org-babel-temp-file "R-"))) + ;; This code borrowed from + ;; `org-babel-comint-eval-invisibly-and-wait-for-file' + (unless (org-babel-comint-buffer-livep session) + (error "Buffer %s does not exist or has no process" session)) + (if (file-exists-p sentinel-file) (delete-file sentinel-file)) + (with-current-buffer session + (let ((ess-execute-in-process-buffer nil)) + (ess-execute (format + " +.org.old.opts <- options(prompt =3D \"# Org babel prompt\\n\", continue = =3D \"# Org babel prompt\\n\") +cat(\"# Org babel begin output\n\") +%s +cat(\"# Org babel end output\n\") +options(.org.old.opts) +rm(.org.old.opts) +file.create(%S) +" + (org-babel-chomp body) + (if (tramp-tramp-file-p sentinel-file) + (tramp-file-name-localname + (tramp-dissect-file-name sentinel-file)) + sentinel-file)) + nil "org-babel-R-output")) + ;; From Tramp 2.1.19 the following cache flush is not necessary + (if (file-remote-p default-directory) + (let (v) + (with-parsed-tramp-file-name default-directory nil + (tramp-flush-directory-property v ""))))) + (while (not (file-exists-p sentinel-file)) (sit-for 0.25)) + ;; End borrowed code. + (with-current-buffer "*org-babel-R-output*" + (goto-char (point-min)) + (search-forward "# Org babel begin output") + (delete-region (point-min) (1+ (point))) + (goto-char (point-max)) + (search-backward "# Org babel end output") + (delete-region (point) (point-max)) + (goto-char (point-min)) + (flush-lines "^$") + (flush-lines "^# Org babel prompt$") + (delete-trailing-whitespace) + (buffer-string)))))) =20 (defun org-babel-R-process-value-result (result column-names-p) "R-specific processing of return value. --=20 2.0.4 --=-=-= Content-Type: text/plain -- Aaron Ecay --=-=-=--