Allign assignment or comment characters

rstudio

#1

Hi all. I'd like to find a way to align the <- or = when selecting several lines of codes. I realized I'm spending a lot of time doing it manually.

So this :

foo <- 1
potatoe <- 22
pneumonoultramicroscopicsilicovolcanokoniosis <- 333

Would be changed into this :

foo                                           <- 1
potatoe                                       <- 22
pneumonoultramicroscopicsilicovolcanokoniosis <- 333

And this:

data.frame(
  foo = 1,
  potatoe = 22,
  pneumonoultramicroscopicsilicovolcanokoniosis = 333)

Would be changed into this :

data.frame(
  foo                                           = 1,
  potatoe                                       = 22,
  pneumonoultramicroscopicsilicovolcanokoniosis = 333)

(don't modify indentation, if several = on same line align first only)

In some cases I'd like also to be able to align comments as well.

So this:

foo <- 1 # foo!
potatoe <- 22 # potatoe!
pneumonoultramicroscopicsilicovolcanokoniosis <- 333 # uh?

Would be changed into this :

foo <- 1                                             # foo!
potatoe <- 22                                        # potatoe!
pneumonoultramicroscopicsilicovolcanokoniosis <- 333 # uh?

I think I can find my way to design an addon but before I invest time on this I thought there might be an existing solution (existing addon, rstudio feature I missed, clever regex replacement, other trick...)?


#2

There isn't anything that I know of (though I'm not much of a sample!). Though it hasn't been updated recently, there is

There was also a thread on community that contains some links, if you wanted to do some more exploring before undertaking the endeavor:

This might be a good question for #rstats twitter.


#3

Thank you Mara I appreciate