Structuring a Statistical Analysis with R Using Emacs/ESS
emacs, ess, r, statistics
Solution
Recent (Feb 2013) additions to Orgmode mean that you should now be able to embed org headings in your source code, and then navigate through them using orgstruct-mode. So, upgrade your org mode via git, and then try opening the following example R file. When you are on a comment line that has an org heading embedded, just hit TAB, or shift-TAB, and you should get org-mode headings.
### * Create data
data = list( s1=list(x=1:3, y=3:1),
s2=list(x=1:5, y=1:5), s3=list(x=1:4, y=rep(3,4)))
### * Base graphics version
par(mfrow=c(2,2))
lapply(data, plot)
### * Lattice version
nplots <- length(data)
pts.per.plot <- sapply(data, function(l) length(l$x))
df <- data.frame(which=rep(1:nplots, times=pts.per.plot),
x=unlist(sapply(data, function(l) l$x)),
y=unlist(sapply(data, function(l) l$y)))
xyplot(y~x|which, data=df, layout=c(2,2))
### ** Make the pdf
pdf(file='o.pdf')
xyplot(y~x|which, data=df, layout=c(2,1))
dev.off()
### * End of file
### Local Variables:
### eval: (orgstruct-mode 1)
### orgstruct-heading-prefix-regexp: "### "
### End:
Problem
I am looking for a way to structure my statistical analysis. I currently use Emacs/ESS and the analysis file turned out quite long. I have started to put parts of the code into sourceable functions in a separate file, but still... I would like to introduce some kind of subheadings/ section titles in the file (Aggregation, Cluster-analysis, Simulations, ...) and write the code beneath it, so I could quickly jump to the sections that I want to work on. I guess I could just use comments and search for them, but I couldn't get an overview or an index that way. I also thought about using Org-Mode for the Headlines, but that wouldn't be very convenient for collaborators, who work with another Editor. I know R-Studio implements this with sections, so there will be a solution for emacs, right? Thank you very much! PS: something like imenu would work, but that's just for functions, not for sections