Sublime Forum

Wrong indentation for R code

#1

The indentation for R code after using Edit -> Line -> Reindent is not like I expect. Expected one is like in RStudio where closing brackets are more to the left when using “lapply()”. The text after “if()” without “{}” should be indented. The closing brackets from function “foo” should be to the left. How can I fix this?

Here is how the code looks in Sublime 3. Function “loo” starts after tab which is wrong.

foo <- function(a){

  if(a == 1)
  a <- 2
  if(a == 2){
    a <- 3
    }else{
      if(a > 10)
      a <- 10
    }
    return(a)
  }


  loo <- lapply(list, function(x){

    if(sum(x) > 10)
    return(NULL)

    })

Here, in RStudio:

foo <- function(a){

  if(a == 1)
    a <- 2
  if(a == 2){
    a <- 3
  }else{
    if(a > 10)
      a <- 10
  }
  return(a)
}


loo <- lapply(list, function(x){
  
  if(sum(x) > 10)
    return(NULL)
  
})

Thank you for any hints!

0 Likes

#2

Check out the indentation settings and modify them accodingly.

docs.sublimetext.info/en/latest/ … f-settings
docs.sublimetext.info/en/latest/ … g-packages
github.com/skuroda/PackageResourceViewer

0 Likes

#3

From what I can tell, there is no support for the magrittr pipe at this point. I am currently using the LSP package and the rlang server.

0 Likes