yihui / formatR

Format R Code Automatically

Home Page:https://yihui.org/formatr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Seems to have put statement on wrong line

Auburngrads opened this issue · comments

Here is the sessionInfo from the run:

R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

The following object is masked from package:base:

    setwd

libraries: c:/R/r_libs-3.2.3 C:/R/R-3.2.3/library 
library & Java environment set from C:\Users\jh52822\Documents\.RProfile
> require(formatR)
Loading required package: formatR
Warning message:
package ‘formatR’ was built under R version 3.2.4 
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] formatR_1.3

loaded via a namespace (and not attached):
[1] tools_3.2.3

I was using the 'utils.R' file from the 'formatR' source code and here is what it gave me on a section of code:

# no blank lines before an 'else' statement!
move_else = function(x) {
    blank = grepl("^\\s*$", x)
    if (!any(blank)) 
        return(x) else.line = grep("^\\s*else(\\W|)", x)   ## **** here is the bad line ****
    for (i in else.line) {
        j = i - 1
        while (blank[j]) {
            blank[j] = FALSE
            j = j - 1  # search backwards & rm blank lines
            warning("removed blank line ", j, " (should not put an 'else' in a separate line!)")
        }
    }
    x[blank] = blank.comment
    x
}

Here was the original source

# no blank lines before an 'else' statement!
move_else = function(x) {
  blank = grepl('^\\s*$', x)
  if (!any(blank)) return(x)
  else.line = grep('^\\s*else(\\W|)', x)   ## **** this is on a separate line ****
  for (i in else.line) {
    j = i - 1
    while (blank[j]) {
      blank[j] = FALSE; j = j - 1  # search backwards & rm blank lines
      warning('removed blank line ', j, " (should not put an 'else' in a separate line!)")
    }
  }
  x[blank] = blank.comment
  x
}

Thanks for the report! Fixed now.