[ESS] A smart ESS function for replacing "=" used for assignment by "<-"
maechler at stat.math.ethz.ch
Sat Nov 12 09:04:02 CET 2011
On Sat, Nov 12, 2011 at 00:59, Seb <spluque at gmail.com> wrote:
> On Fri, 11 Nov 2011 17:07:23 -0600,
> Douglas Bates <bates at stat.wisc.edu> wrote:
>> I am editing code from another person who uses "=" as the assignment
>> operator. For the sake of my sanity I want to change those uses of
>> "=" to "<-" but, of course, only those uses of "=". I can use
>> query-replace but I seem to remember a smart ESS function that would
>> replace those instances of "=" but not other instances. I can't find
>> such a function in the documentation. Am I hallucinating or is there
>> such a function?
> Absolutely, that's `ess-fix-EQ-assign', and there are a couple other
> `ess-fix-*', which can be performed together with `ess-MM-fix-src'.
> Thanks to Martin Maechler for these sanity savers!!
Well, thank for the flowers...
Note however, that the fix-EQ-assign is far from perfect.
It uses "robust heuristics" and has to be run in "query" mode, because
of both kinds (false positive / false negative).
If you only look locally, it's hard to see that
def = ......
ghi = ......
has two "=" signs that should not be replaced;
foobar(object) = pqrs(..sdfs.df.s.df.s...)
is typically not detected as a form of 'foobar<-' by "my" function.
A better solution nowadays (where computers and Emacs and R in
particular are much faster),
would probably use R to parse the complete code and then work with
parse tree (or parse "forest": each toplevel expression a tree) to
distinguish the assignment "=" from the function argument setting
> ESS-help at r-project.org mailing list
More information about the ESS-help