Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refactoring R code using ESS/R

Tags:

emacs

r

elisp

ess

I would like to know if it is possible to refactor R code in ESS. Using search and replace in Emacs does not seem to be a good alternative to it.

like image 452
ggg Avatar asked Jun 05 '10 01:06

ggg


2 Answers

ESS itself does not provide any facilities for refactoring. Instead you can use emacs functionality.

Here is an example of how to replace all words starting with "xxx" and ending with "yyy" with "zzzzzz" in all your open R files in your project directory.

  • C-x d (enter dired)

  • % m r$ (mark all files ending in R or r)

  • Q (enter dired-to-query-replace-regexp)

  • type xxx.*zzz and zzzzzz when asked for replacement patterns.

  • accept, skip with y,n

Here is a complete tutorial of how to search-replace in multiple files. and also how to save all modified buffers with ibuffer.

like image 150
VitoshKa Avatar answered Nov 04 '22 21:11

VitoshKa


In Emacs you can do a search replace with M-% and then ! will replace every instance in the current buffer.

If that isn't want you mean, can you explain (edit your Q or comment here) what Statet does and what exactly you'd like to do in Emacs + ESS?

like image 2
Gavin Simpson Avatar answered Nov 04 '22 22:11

Gavin Simpson