How can I use Emacs ESS mode with R markdown?

前端 未结 3 1319
既然无缘
既然无缘 2021-01-30 04:59

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 .R

3条回答
  •  醉酒成梦
    2021-01-30 05:35

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

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

    Add this function to your Emacs init file:

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

    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:

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

提交回复
热议问题