[ESS] A smart ESS function for replacing "=" used for assignment by "<-"
Martin Maechler
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
there errors
of both kinds (false positive / false negative).
If you only look locally, it's hard to see that
myfun(abc,
def = ......
....,
ghi = ......
)
has two "=" signs that should not be replaced;
OTOH,
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
"=".
Martin
>
> --
> Seb
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
>
>
More information about the ESS-help
mailing list