ESS (emacs speaks statistics) is a package for (X)emacs which knows how to format R files correctly (R mode). It also allows you to call R from inside an emacs shell.
Here I provide brief instructions on how to install ESS, assuming you have already installed Xemacs and R.
(load "C:/Program Files/XEmacs/xemacs-packages/lisp/ess/ess-5.2.9/lisp/ess-site")To check this work, restart emacs and open a file with a .R or .r extension: it should format it properly (with color) and say "ESS[S]" at the bottom line of the window to indicate that emacs is in ESS mode.
For instructions on how to use ESS, see An introduction to ESS + Xemacs for Windows Users of R by John Fox.