formatR
formatR copied to clipboard
Comments not formatted properly into multiple lines when there is an expression in a line before a comment when a line length including comments exceeds the maximum line width value
When I enter an expression in a line that has a comment after an expression when the line length exceeds the maximum line width value, it doesn't formatted into multiple lines. Instead, it formatted into a single line. For example:
0 ## here is a long long long long long long long long long long long long long long long long long long long long comment
Actual formatted output:
## here is a long long long long long long long long long long long
## long long long long long long long long long comment
Another example:
0 ## here is a long long long long long long long long long long long long long long long long long long long long comment
Actual formatted output:
0 ## here is a long long long long long long long long long long long long long long long long long long long long comment
Expected formatted output:
0 ## here is a long long long long long long long long long long long
## long long long long long long long long long comment
By filing an issue to this repo, I promise that
- [x] I have fully read the issue guide at https://yihui.org/issue/.
- [x] I have provided the necessary information about my issue.
- If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
- If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included
xfun::session_info('formatR'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/formatR'). - If I have posted the same issue elsewhere, I have also mentioned it in this issue.
- [x] I have learned the Github Markdown syntax, and formatted my issue correctly.
I understand that my issue may be closed if I don't fulfill my promises.
Another example that fails to parse the code but the code is correct with no syntax errors:
c(a,#a
b#b
)
Expected formatted output:
c(a, # a
b # b
)
Error message:
Error in base::parse(text = code, keep.source = keep.source) :
<text>:1:9: unexpected SPECIAL
Another formatting error:
a(#a
)
Actual output:
Error in base::parse(text = code, keep.source = keep.source) :
<text>:1:5: unexpected SPECIAL
1: a ( %
Expected formatted output:
a( #a
)
For the first problem, formatR is not intelligent enough to move an inline comment to a block comment. You have to use a block comment in the original source.
For the second and third problems, that's a known limitation: https://yihui.org/formatr/#6-further-notes