Align either pre-defined or user-input regular expressions. This is a port of AlignAssign.
Use only one \
when searching for literals.
# i.e.
# Use...
"[A-Z]+\s"
# ...instead of...
"[A-Z]+\\s"
# ...to search for a letter followed by a space.
Be mindful that highling a chunk of code which has assignment operators within commented lines, like the following, and running the Align <-
addin...
# This is a commented line with an assignment operator <-
a <- 1:5
b <- 6:10
c <- 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:5
b <- 6:10
c <- 11:15
# There is an assignment operator <- here, too
There is also no special handling of assignment operators within a function. So, if you highlighted the entire chunk below and then ran the Align <-
addin...
var1 <- letters
var2 <- 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 <- NA
matched
})
return(matches)
}
positions <- list.pos(c("a", "bbb", "c"), var2)
...the result will look like this.
var1 <- letters
var2 <- 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 <- NA
matched
})
return(matches)
}
positions <- list.pos(c("a", "bbb", "c"), var2)
- Use shinyalert to handle cases where no regex match occurs, too few lines have been selected, and other errors and warnings that may occur.