[ESS] A smart ESS function for replacing "=" used for assignment by "<-"

Yihui Xie xie at yihui.name
Sun Nov 13 04:27:00 CET 2011


The formatR package can do the trick based on the parser package, e.g.

library(formatR)
tidy.source(text = 'x=1;plot(x=1:10)', replace.assign = TRUE)
## you get this:
## x <- 1
## plot(x = 1:10)

The first argument of tidy.source() can be the file path of your script.

BTW, it is good to know I'm not the only one who insists on using =
instead of <-. Please say hello to him/her for me :)

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Fri, Nov 11, 2011 at 5:07 PM, 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?
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
>



More information about the ESS-help mailing list