这是一个“经典的”Rmd文件的改编,我想编织成一个pdf使用Emacs ()和多模式。我找不到正确的命令来做到这一点。几乎没有关于多模的文档。我正在为社会科学使用Emacs初学者工具包。
---
title: "Untitled"
author: "SB"
date: "Wednesday, February 04, 2015"
output: pdf_document
---
You can embed an R code chunk like this:
```{r}摘要(Cars)
You can also embed plots, for example:
```{r, echo=FALSE}阴谋(汽车)
发布于 2017-12-11 20:56:08
您可以使用rmarkdown::render()从rmarkdown包编织一个.Rmd文件来标记并呈现输出文件(PDF、Word、HTML等)。只有一个命令!
我不确定ESS中是否已经包含了对rmarkdown工作流的支持(我正在尝试使用elisp),因此我编写了一个函数,它调用rmarkdown::render()并允许使用前缀arg (例如,C-u)定制rmarkdown::render()函数调用的输入。
;; spa/rmd-render
;; Global history list allows Emacs to "remember" the last
;; render commands and propose as suggestions in the minibuffer.
(defvar rmd-render-history nil "History list for spa/rmd-render.")
(defun spa/rmd-render (arg)
"Render the current Rmd file to PDF output.
With a prefix arg, edit the R command in the minibuffer"
(interactive "P")
;; Build the default R render command
(setq rcmd (concat "rmarkdown::render('" buffer-file-name "',"
"output_dir = '../reports',"
"output_format = 'pdf_document')"))
;; Check for prefix argument
(if arg
(progn
;; Use last command as the default (if non-nil)
(setq prev-history (car rmd-render-history))
(if prev-history
(setq rcmd prev-history)
nil)
;; Allow the user to modify rcmd
(setq rcmd
(read-from-minibuffer "Run: " rcmd nil nil 'rmd-render-history))
)
;; With no prefix arg, add default rcmd to history
(setq rmd-render-history (add-to-history 'rmd-render-history rcmd)))
;; Build and evaluate the shell command
(setq command (concat "echo \"" rcmd "\" | R --vanilla"))
(compile command))
(define-key polymode-mode-map (kbd "C-c r") 'spa/rmd-render)请注意,我有一些特定的参数设置,比如output_dir = '../reports',但是可以很容易地定制这个参数以满足您的需要。
在init文件中这样做,只需要在C-c r文件中输入.Rmd (或将C-u C-c r呈现为不同的格式、位置等)。该命令将使用名为*compilation*的缓冲区打开一个新窗口,在该窗口中将出现任何错误。
这肯定是可以改进的,我很想听听你的建议。
https://stackoverflow.com/questions/28324288
复制相似问题