Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty lines in function calls results in an error #94

Open
3 tasks done
Iain-S opened this issue Mar 22, 2022 · 3 comments
Open
3 tasks done

Empty lines in function calls results in an error #94

Iain-S opened this issue Mar 22, 2022 · 3 comments

Comments

@Iain-S
Copy link

Iain-S commented Mar 22, 2022

R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Locale: en_GB.UTF-8 / en_GB.UTF-8 / en_GB.UTF-8 / C / en_GB.UTF-8 / en_GB.UTF-8
Package version:
formatR_1.11.1

Minimal Reproducible Example

At least some of the time (perhaps all of the time) having two empty lines between function call parens causes formatR to error. However, it appears to be valid R syntax (verified by running it in R).

mre.R

print(


)
> formatR::tidy_file("mre.R", indent=2, arrow=TRUE, args.newline=TRUE)
tidying mre.R
Error in base::parse(text = code, keep.source = FALSE) :
  <text>:3:1: unexpected symbol
2: invisible(".BeGiN_TiDy_IdEnTiFiEr_HaHaHa.HaHaHa_EnD_TiDy_IdEnTiFiEr")
3: invisible

Conversely, having only one empty line in the function call does not throw an error but does result in incorrect behaviour

mre2.R (before)

print(

)
> formatR::tidy_file("mre2.R")
tidying mre2.R

mre2.R (after)

print() print()

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • 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.
  • 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.

@yihui
Copy link
Owner

yihui commented Mar 23, 2022

I'm afraid that this is a known limitation: https://yihui.org/formatr/#6-further-notes Not all blank lines can be correctly formatted. Sorry.

@Iain-S
Copy link
Author

Iain-S commented Mar 23, 2022

OK, thanks. I can see that the files are correctly formatted if I set blank=FALSE and comment=FALSE.

Do you think that the whitespace formatting could be improved or is it a limitation of R, as a language?

@yihui
Copy link
Owner

yihui commented Mar 23, 2022

It's not a limitation of R, but me. I feel it would be hard to support multiple empty lines as in your first example. For the second example, it looks like a bug. I don't know why two instances of print() were generated. @iqis Do you have time to investigate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants