Search code examples
reditor

Rename function simultaneously in R


I am developing R package, and wish to change the name of a function. How could I set the project up such that the function name can be changed simultaneously in all different files where the function is called? Should I use some particular editor, like Emacs? I am using RStudio.


Solution

  • It appears that RStudio does not currently have the capability to do global variable renaming, q.v. this page.

    However, you will likely be safe just doing a find and replace in all files for the name of function followed by an open parenthesis.

    For example, if your function is called myFunc and you want to rename it to newFunc then you can do the following replacement:

    myFunc( -> newFunc(
    

    Include the parenthesis to make sure that you are replacing only the function definition and calls, and not the string myFunc in some other context.