Emacs ESS:从R REPL到缓冲区的管道输出

时间:2016-11-14 13:04:34

标签: r emacs pipe read-eval-print-loop ess

我希望能够在R的REPL上执行语句,并可选择将其传递给缓冲区,以便稍后再快速参考。

要运行shell命令并输出到*shell command buffer*,我可以按this question使用M-!。如果不诉诸write.csv(),R的REPL会等同于什么?

1 个答案:

答案 0 :(得分:0)

您可以使用ess-command中的ess-inf将输出重定向到另一个缓冲区。示例可能如下所示,

(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))))