I am attempting to add spaces to a messy R file to clean it up. We have:
a <- b
g<-h
q <- my_df[,c(1:5)]
j<- k%>%
mutate(mm = 'new col')%>%
mutate(nn = 'new col') %>%
mutate(oo = 'new col')
desired output is:
a <- b
g <- h
q <- [, c(1:5)]
j <- k %>%
mutate(mm = 'new col') %>%
mutate(nn = 'new col') %>%
mutate(oo = 'new col')
To summarise:
- space before / after
<-
, but of course don't add these spaces if they already exist - space before
%>%
- space after
,
It seems like the best option is to search and replace using RStudio's built in tool, and to use the Regex feature specifically. However, I'm not quite sure how to write the right Regex pattern for these subs without messing anything else up.