Script to indent R code
I was looking for a way to indent my R code, since the R auto-packaging command inserted a bunch of hard tabs and anyways the code was messy.
I found this page describing a way to do it with ESS (Emacs Speaks Statistics). So, I downloaded ESS from the ESS homepage and adapted the script slightly to be a simple shell-script.
#!/bin/sh
# Use emacs ESS pkg to indent R file
# Dan Gunter, Dec 2008
function usage () {
printf "Indent R file with Emacs ESS package.\n"
printf "Usage: $0 FILE\n"
exit 1
}
f=$1
shift
if test "x$f" = x -o "x$f" = "x-h"; then
usage
fi
emacs -batch \
-eval '(load "/Users/dang/local/lib/emacs/ess-5.3.8/lisp/ess-site")' \
-f R-mode \
-eval '(insert-file "'${f}'")' \
-eval '(set-visited-file-name "'"${f}"'")' \
-eval '(indent-region (point-min) (point-max) nil)' \
-f save-buffer \
2>/dev/null

Doh! A simpler and probably better way is documented in the R extension manual (section 3.1)
options(keep.source = FALSE)
source(”myfuns.R”)
dump(ls(all = TRUE), file = “new.myfuns.R”)
@dang
your solution doesn’t indent the code, it only dumps the variables….