Editing script in the Source window using Find/Replace (Ctrl + shift + J)

Call me "Flummoxed".

BACKGROUND:
I have a script that I wrote when I was learning R. In this script, I used gsub() to replace errors in the contents of character variables. This works but is very slow because it's a very long script and the contents of character variables are very dirty.

Now that I'm more experienced, I have discovered case_when, which is much more efficient so it takes significantly less time to run the script.

GOAL:
I want to convert the old "gsub" code to "case_when" code by using Find/Replace (Ctrl + shift + J) in the Source Window to edit the code rather than typing the whole darned thing in again.

PROBLEM:
For the first step in the conversion, I want to condense the gsub() command onto one line by replacing the new line and space between "<-" and "gsub" with only a space. Doing this makes the subsequent conversion steps very easy.

And therein lies the rub....I can't figure out how to do the above.

QUESTION:
How do I "find" a new line (?? /n ??) in the "FIND" box of Find/Replace?

#read in data
      parties <- c("frist bank", "other bank", "third bank", "fourth bank")
      parties <- as_tibble(parties)
      names(parties)[1] <- 'Name'

#I WANT TO REPLACE THIS:
      parties$Name <-
        gsub('frist bank', 'first bank', parties$Name)

#WITH THIS:  (remove the new line and space between   <-  and gsub)
       parties$Name <- gsub('frist bank', 'first bank', parties$Name)

#THEN PROCEED WITH CONVERTING TO CASE_WHEN....*
  • I have identified these commands. It's only the first "gsub" step that is the problem.

Thanks in advance for your help and suggestions.

Linda - uh, I mean Flummoxed

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.