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

how to split the parameters into different lines and keep them aligned? #57

Open
fyears opened this issue Aug 15, 2016 · 9 comments
Open

Comments

@fyears
Copy link

fyears commented Aug 15, 2016

After using "format code" in the latest RStudio, the parameters of functions are split into different lines and kept aligned.

But I am unable to find the corresponding settings in formatR package. How to do it with formatR?

Consider the source code:

my_sum = function(a = 1, b = 2, c =3) {
  return(a + b + c)
}

The desired formatted result (RStudio returns this):

my_sum = function(a = 1,
                  b = 2,
                  c = 3) {
  return(a + b + c)
}
@yihui
Copy link
Owner

yihui commented Aug 15, 2016

formatR cannot do that...


Reminder to self: update this post when this feature is implemented.

@jfiksel
Copy link

jfiksel commented Feb 9, 2017

I second adding this feature if possible, since this is the correct way to write functions with multi-line parameters

@yihui
Copy link
Owner

yihui commented Feb 9, 2017

I wouldn't say "it is the correct way", but it is definitely a favorable style to many people.

I don't feel the implementation is easy, so I'll leave this task to contributors...

@fyears
Copy link
Author

fyears commented Feb 9, 2017

I checked out the potential solutions before. It was definitely harder than I think: a basic parser understanding R syntax is needed, rather than any "text processing" logics...

@yihui
Copy link
Owner

yihui commented Feb 9, 2017

Exactly. You cannot do this only through regular expressions or any text processing techniques. A parser has to be involved.

@jfiksel
Copy link

jfiksel commented Feb 9, 2017

Hm, that sounds way above what I would be capable of doing. It seems that RStudio already implements this, but I am only asking because I have been trying to write R code in Atom for a project that I have to use a remote cluster for. It seems that the atom-beautify package implements formatR for formatting R code

@yihui
Copy link
Owner

yihui commented Feb 10, 2017

If someone can figure out the RStudio magic, and it turns out not be super difficult to implement in pure R, I'd welcome a pull request. Personally I don't have time or enough interest in this feature.

@naught101
Copy link

It's this basically a duplicate of #53?

@yihui
Copy link
Owner

yihui commented Mar 22, 2017

@naught101 Yes.

I can tell you that RStudio actually uses JavaScript to reformat the R code, so the magic cannot be directly ported to formatR.

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

4 participants