如何使用Emacs ESS模式和R markdown?

时间:2021-08-04 14:56:37

Is there a way to configure Emacs so that it recognizes (and allows execution of) R code chunks within R markdown (.Rmd) files similar to the way it recognizes code chunks in .Rnw (Sweave) or .org (org-mode) files?

有没有一种方法可以配置Emacs,使它能够识别(并允许执行)R代码块在R markdown (.Rmd)文件中,就像它识别.Rnw (Sweave)或.org (org-mode)文件中的代码块一样?

2 个解决方案

#1


28  

polymode is being developed which does/will allow you to write markdown with R chunks (for processing with knitr).

正在开发polymode,它允许您使用R块(用于使用knitr处理)编写markdown。

Instructions for setting up polymode+rmarkdown are in the README

设置polymode+rmarkdown的说明在README中

It is not yet done, but is progressing. See also this discussion on the ess-help mailing list (gmane archive|mailing list archive)

这项工作尚未完成,但正在取得进展。还请参阅关于国际象棋帮助邮件列表的讨论(gmane归档|邮件列表归档)


Update: polymode has been released on MELPA, simplifying the installation process by using emacs' existing package mechanism. See the announcement on the ESS mailing list here.

更新:在MELPA上发布了polymode,使用emacs现有的包机制简化了安装过程。请参见这里的ESS邮件列表。

#2


17  

Download the zip for polymode from github.com/vitoshka/polymode or, if you are a "git guy", you might use:

从github.com/vitoshka/polymode下载polymode的zip,如果你是“git guy”,你可以使用:

git clone https://github.com/vitoshka/polymode.git

Add this function to your Emacs init file:

将此功能添加到您的Emacs init文件:

(defun rmd-mode ()
  "ESS Markdown mode for rmd files"
  (interactive)
  (setq load-path 
    (append (list "path/to/polymode/" "path/to/polymode/modes/")
        load-path))
  (require 'poly-R)
  (require 'poly-markdown)     
  (poly-markdown+r-mode))

Now, if you already have ESS installed, just open your rmd file and type Meta-Xrmd-mode and watch the beauty of Emacs.

现在,如果您已经安装了ESS,那么只需打开rmd文件并键入元xrmd模式,并观察Emacs的美妙之处。

Update for MELPA users

polymode from MELPA uses a flat file structure. When you install from an Emacs repository via M-x list-packages or like facilities, you get your package files straight where they ought to, i.e.: (expand-file-name "~/.emacs.d/elpa"), therefore do comment the above load-path code:

来自MELPA的polymode使用平面文件结构。当您通过M-x列表包或类似的工具从Emacs存储库安装时,您可以直接将包文件放在应该的位置,即。:(扩展-文件-名称"~/.emac .d/elpa"),因此请对上面的加载-路径代码进行注释:

;;  (setq load-path 
;;      (append (list "path/to/polymode/" "path/to/polymode/modes/")
;;          load-path))

#1


28  

polymode is being developed which does/will allow you to write markdown with R chunks (for processing with knitr).

正在开发polymode,它允许您使用R块(用于使用knitr处理)编写markdown。

Instructions for setting up polymode+rmarkdown are in the README

设置polymode+rmarkdown的说明在README中

It is not yet done, but is progressing. See also this discussion on the ess-help mailing list (gmane archive|mailing list archive)

这项工作尚未完成,但正在取得进展。还请参阅关于国际象棋帮助邮件列表的讨论(gmane归档|邮件列表归档)


Update: polymode has been released on MELPA, simplifying the installation process by using emacs' existing package mechanism. See the announcement on the ESS mailing list here.

更新:在MELPA上发布了polymode,使用emacs现有的包机制简化了安装过程。请参见这里的ESS邮件列表。

#2


17  

Download the zip for polymode from github.com/vitoshka/polymode or, if you are a "git guy", you might use:

从github.com/vitoshka/polymode下载polymode的zip,如果你是“git guy”,你可以使用:

git clone https://github.com/vitoshka/polymode.git

Add this function to your Emacs init file:

将此功能添加到您的Emacs init文件:

(defun rmd-mode ()
  "ESS Markdown mode for rmd files"
  (interactive)
  (setq load-path 
    (append (list "path/to/polymode/" "path/to/polymode/modes/")
        load-path))
  (require 'poly-R)
  (require 'poly-markdown)     
  (poly-markdown+r-mode))

Now, if you already have ESS installed, just open your rmd file and type Meta-Xrmd-mode and watch the beauty of Emacs.

现在,如果您已经安装了ESS,那么只需打开rmd文件并键入元xrmd模式,并观察Emacs的美妙之处。

Update for MELPA users

polymode from MELPA uses a flat file structure. When you install from an Emacs repository via M-x list-packages or like facilities, you get your package files straight where they ought to, i.e.: (expand-file-name "~/.emacs.d/elpa"), therefore do comment the above load-path code:

来自MELPA的polymode使用平面文件结构。当您通过M-x列表包或类似的工具从Emacs存储库安装时,您可以直接将包文件放在应该的位置,即。:(扩展-文件-名称"~/.emac .d/elpa"),因此请对上面的加载-路径代码进行注释:

;;  (setq load-path 
;;      (append (list "path/to/polymode/" "path/to/polymode/modes/")
;;          load-path))