You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Align the assignment operators (either<- or=) within a highlightedarea.
Before:
a<-1:5bbb<-6:10c<-letters
After:
a<-1:5bbb<-6:10c<-letters
Align Cursors
For alignment of any text, you can align multiple cursors with theAlign Cursors addin. Add multiple cursors to your document byholdingCtrl/Cmd +Alt and clicking inthe RStudio editor, or by holdingAlt and clicking anddragging the mouse.
What
AlignAssign contains three addins. Two addins align all of either the<- (Align Assign) or= (Align Assign 2) assignment operatorswithin a highlighted region and the third aligns multiple cursors acrosslines to the same column.
None of the addins “reflow” your code if the alignment breaks the pagewidth. They also does not treat commented lines differently touncommented lines.If there is either one of the assignment operatorswithin a highlighted comment line, then it will either align thatoperator or align other operators to it.
Install
devtools::install_github("seasmith/AlignAssign")`
You can assign each alignment addin action to a specific keyboardshortcut in RStudio in theModify keyboard shortcuts… menu optionunder theTools menu.
Examples
Align<-’s with Align Assign
When you highlight the following chunk of code (region) - whether youhighlight the entirity or just a portion of the first and last lines -and then run theAlign Assign addin…
# This is a commented line# So is thisa<-1:5b<-6:10copy_a<-a# More comments
…the result will look like this.
# This is a commented line# So is thisa<-1:5b<-6:10copy_a<-a# More comments
Align=’s with Align Assign 2
The above example also works for the= operator when using the otheraddin,Align Assign 2. Before…
Be mindful that highling a chunk of code which has assignment operatorswithin commented lines, like the following, and running theAlign Assign 2 addin…
# This is a commented line with an assignment operator <-a<-1:5b<-6:10c<-11:15# There is an assignment operator <- here, too
…will result in something like this.
# This is a commented line with an assignment operator <-a<-1:5b<-6:10c<-11:15# There is an assignment operator <- here, too
Not so smart aligner
There is also no special handling of assignment operators within afunction. So, if you highlighted the entire chunk below and then ran theAlign Assign addin…