yihui / formatR

Format R Code Automatically
https://yihui.org/formatr/
256 stars 52 forks source link

Correctly Wrap Comments According to Width Cutoff #92

Closed iqis closed 3 years ago

iqis commented 3 years ago

Wraps comment lines after indentation is performed on a comment line to keep it confined to specified width.

iqis commented 3 years ago

How tests fail currently:

in test-tidy.R

> tidy.res(c('if(TRUE){1+1', '', '}', '', '# a comment'))
[1] "if (TRUE) {\n    1 + 1\n     \n}" " "                               
[3] "# a comment"    

spaces are added between the \ns after 1+1 compared to c('if (TRUE) {\n 1 + 1\n\n}', '', '# a comment')

> tidy.res(x1, width.cutoff = 20)
[1] "# a b c d e f g h i\n# j k l m n o p q r\n# s t u v w x y z"

Seems to have been pasted with \n while the desired is c('# a b c d e f g h i j', '# k l m n o p q r s t', '# u v w x y z')

yihui commented 3 years ago

@iqis Just to let you know, I plan to make a new CRAN release to support the native pipe (3f7656f00d34d3610d96626c19e486e5d5348c7a) this week, so I'll see if I can finish revising this PR by myself and include it in the next release. Thanks!