2

I want to have the ability to execute statements on R's REPL with the option to pipe it to a buffer so I can quickly refer back to it later.

To run a shell command and output to *shell command buffer* I can use M-! as per this question. What would the equivalent be for R's REPL without resorting to write.csv()?

1 Answer 1

0

You can use ess-command from ess-inf to redirect the output to another buffer. An example could look like the following,

(defun redirect-ess-output (command &optional buffer process)
  (interactive (list (read-from-minibuffer "Command: ")))
  (let ((buff (get-buffer-create (or buffer "*r-output*")))
        ;; 'ess-get-process' defaults to process local to current
        ;; buffer, so to call from anywhere default to "R"
        (proc (ess-get-process (or process "R"))))
    ;; send a trailing newline to process
    (unless (string-match-p "\n$" command)
      (setq command (concat command "\n")))
    (ess-command command buff 'sleep nil nil proc)
    (with-current-buffer buff
      ;; process stuff
      (pop-to-buffer buff))))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.