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.
installation
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")
load-path))
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
\documentclass[a4]{scrartcl}
\begin{document}
Here is a code chunk.
<<demo, fig.height=4,message=FALSE,warning=FALSE>>=
library(ggplot2)
summary(cars)
qplot(speed,dist,data=cars) +
geom_smooth()
@
You can also write inline expressioins, e.g. $\pi=\Sexpr{pi}$.
\end{document}
Notes
- Windows 7 32 bit
- Polymode updated from MELPA
Update
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")
load-path))