Polymode is very promising to handle the integration of R chunks using different modes.
I went through the documentation and it works well when I am inside .Rmd file but not inside .Rnw. In the .Rnw I found the Noweb mode activated without polymode PM-rmd. So there must be something wrong with my installation on Windows machine.

I installed rmarkdown-mode from MELPA, BTW this was not shown clearly in the documentation of polymode, I wish there was a requirement section in it.

I was confused about that part of installation:

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

Because in Windows, polymode resides in c:/emacs/.emacs.d/elpa/polymode-20150105.931/ but I don't see the \modes folder in there! So is the above code needed if I had used install-packages from MELPA?

I installed the polymode package from MELPA. M-x list packages.

I have pandoc installed and checked in the PATH variables by M-x getenv RET PATH RET; pandoc was there.

relevant .init.el code

(require 'poly-R)
(require 'poly-markdown)
;; Markdown
(add-to-list 'auto-mode-alist '("\\.md" . poly-markdown-mode))

;;; R related modes
(add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode))
(add-to-list 'auto-mode-alist '("\\.Rmd" . poly-markdown+r-mode))
(setq ess-swv-processing-command "%s(%s)") % this to get rid of .ess_weave() function not found error  

MWE of .Rnw file

  Here is a code chunk.
<<demo, fig.height=4,message=FALSE,warning=FALSE>>=
qplot(speed,dist,data=cars) +
You can also write inline expressioins, e.g. $\pi=\Sexpr{pi}$.


  • Windows 7 32 bit
  • Polymode updated from MELPA

I used this code right after ESS code in the init.el and it worked well:

(require 'poly-R)
(require 'poly-markdown)
(add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode))

I realized that for MELPA installation these lines of code in the documentation are irrelevant:

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

1 Answer 1


You need to add poly-noweb+r-mode to auto-mode-alist for Rnw files. You also need to watch for conflicts with ESS. ESS adds its own mode to auto-mode-alist for Rnw files, so you have to wait until after this happens to make sure you over-ride the ESS settings. This is what I have in my .emacs:

(require 'polymode)
(require 'poly-R)
(eval-after-load 'ess-site 
     (add-to-list 'auto-mode-alist '("\\.[rR]md" . poly-markdown+r-mode))
     (add-to-list 'auto-mode-alist '("\\.[rR]nw" . poly-noweb+r-mode)))
  • is it necessary to put this code after ESS code in the init.el file or doesn't matter?
    – doctorate
    Commented Feb 13, 2015 at 21:04
  • It shouldn't matter - (eval-after-load ...) should hold off on cleaning up the ess stuff until after it has loaded. Just to be safe, I'll edit it to put the next line into the same form.
    – Tyler
    Commented Feb 13, 2015 at 21:06
  • 1
    @doctorate, @Tyler You need not put all the (requre ..)s, poly-R should be enough. Also deleting Rnw-mode is not necessary, the first assignment in auto-mode-alist takes precedence.
    – VitoshKa
    Commented Feb 13, 2015 at 21:16
  • Thanks @VitoshKa ! And thanks for polymode, it's fantastic
    – Tyler
    Commented Feb 13, 2015 at 21:47
  • I confirm that there is no need to require (polymode). I just put the code after the ESS code and it worked well (as in the update).
    – doctorate
    Commented Feb 14, 2015 at 16:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.