Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Align the assignment operators within a highlighted area.

NotificationsYou must be signed in to change notification settings

seasmith/AlignAssign

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

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…

# Perosnal informationlist(surname="Crichton",firstName="John",address=NA,occupation="fugitive")

…after.

# Perosnal informationlist(surname="Crichton",firstName="John",address=NA,occupation="fugitive")

Behavior of commented-out assignment operators

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…

var1<-lettersvar2<- as.list(sample(1:26,26))names(var2)<-var1[unlist(var2)]list.pos<-function(name,lst){matches<- sapply(name,function(x){matched<- which(names(lst)%in%x)if(length(matched)==0)matched<-NAmatched    })return(matches)}positions<- list.pos(c("a","bbb","c"),var2)

…the result will look like this.

var1<-lettersvar2<- as.list(sample(1:26,26))names(var2)<-var1[unlist(var2)]list.pos<-function(name,lst){matches<- sapply(name,function(x){matched<- which(names(lst)%in%x)if(length(matched)==0)matched<-NAmatched    })return(matches)}positions<- list.pos(c("a","bbb","c"),var2)

About

Align the assignment operators within a highlighted area.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp