Search code examples
rrstudioshortcut

R: select and change the name of an object in a script that appears multiple times (shortcut?)


I would like to know if there is a shortcut to change the name of an object in Rstudio that appears multiple times in a script. For example, if I start with:

x*y
y <- x + 4
x <- x + y

This is just some meaningless code. Suppose I would like to have z instead of x :

z*y
y <- z + 4
z <- z + y

Is there a way of changing all the x to z silmultaneously , instead of one at the time? This would be very useful for longer scripts.


Solution

  • When you like to change x to z in Rstudio

    1. press [Ctrl] + [f]
    2. put the name of the old variable... in your case press just [x]
    3. press [tab] to change to the 'replace' field
    4. put the name of the new variable name

    Take care that you dont change, when the string is only part of other functions or variables