[ESS] ESS for code tidying

Martin Maechler maechler at stat.math.ethz.ch
Fri Feb 2 23:09:59 CET 2007


>>>>> "Vaidotas" == Vaidotas Zemlys <mpiktas at gmail.com>
>>>>>     on Fri, 2 Feb 2007 17:39:18 +0200 writes:

    Vaidotas> On 2/2/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:

    >> On Fri, 2 Feb 2007, Vaidotas Zemlys wrote:
    >> 
    >> > Hm, I copied this code directly from Emacs+ESS, maybe the mailer
    >> > mangled something. What I want to do with this piece of code (I will
    >> > repaste it here)
    >> >
    >> > testf<- function(formula) {
    >> >   mainform <- formula
    >> >   if(deparse(mainform[[3]][[1]])!="|") stop("invalid conditioning")
    >> >   mmodel <- substitute(y~x,list(y=mainform[[2]],x=mainform[[3]][[2]]))
    >> >   mmodel <- as.formula(mmodel)
    >> >   list(formula=list(main=mmodel))
    >> > }
    >> 
    BDR> You use no spaces around your operators or after commas.  R does when
    BDR> deparsing:
    >> 
    >> > testf
    >> function (formula)
    >> {
    >> mainform <- formula
    >> if (deparse(mainform[[3]][[1]]) != "|")
    >> stop("invalid conditioning")
    >> mmodel <- substitute(y ~ x, list(y = mainform[[2]], x = mainform[[3]][[2]]))
    >> mmodel <- as.formula(mmodel)
    >> list(formula = list(main = mmodel))
    >> }
    >> 
    BDR> because it is (at least to old hands) much easier to read.
    BDR> 
    BDR> IcanreadEnglishtextwithoutanyspacesbutIchoosenotto.Similarly,Rcode.Occasional
    BDR> spacesare evenharderto parse.
    BDR> 

    Vaidotas> Sorry for that, it is an old bad habit of
    Vaidotas> mine. I'll try to get rid of it. Does anybody
    Vaidotas> know, if ESS can do this automatically, besides
    Vaidotas> automatical identing?

Yes, partly, though not very officially - partly I think because
the functionality is not 100% water proof:
There are - hidden, partly on purpose - utility features in ESS such
as
     M-x ess-fix-miscellaneous
and (even more purposedly "hidden")
     M-x ess-MM-fix-source

The first of those two does a big part of what Brian likes.
It does not yet add a space after "," -- something I seem to
have needed rarely, probably since most people do add a
space there themselves.  

If you look at the ESS source, for these e.g. available online
in
	https://svn.R-project.org/ESS/trunk/lisp/essl-s.el
you can see that these two functions are built of several
individual tasks and the MM-fix-source one e.g. calls 
ess-fix-EQ-assign something I have found useful but other will
detest. 

I'm open for suggested improvements, notably to the
"fix-misceallaneous" function, but not in the next 10 days (nor
in the 4 subsequent weeks where I'll be at the DSC workshop and
mostly vacationing). 
But then there's the full ESS-core team who can add the
improvements to the sources.

Martin Maechler (MM), ETH Zurich




More information about the ESS-help mailing list