[ESS] Yet another indentation question: indentation after parenthese

Mathieu Basille basille at ase-research.org
Fri Dec 16 15:01:40 CET 2011


Le 16/12/2011 08:49, Vitalie Spinu a écrit :
> Mathieu Basille <basille at ase-research.org> writes:
> 
>> Dear Vitalie,
>>
>> Thanks for you comment. My first message was not perfectly clear... Your
>> example with 'foo' is misleading, since foo is exactly 3 character long.
>> Take this silly example instead:
>>
>> foo <- function(aaaaaaaaaa = 1, bbbbbbbbbb = 2, cccccccccc = 3,
>>                 dddddddddd = 4, eeeeeeeeee = 5)
>> {
>>     return(data.frame(aaaaaaaaaa, bbbbbbbbbb, cccccccccc, dddddddddd,
>>                       eeeeeeeeee))
>> }
>>
>> The new line formatted by ESS starts just after the opening parenthesis.
>> If I save the file in bla.R and source it with 'keep.source = FALSE' to
>> use the R parser, here is what I get:
>>
>>> options(keep.source = FALSE)
>>> source("bla.R")
>>> foo
>> function (aaaaaaaaaa = 1, bbbbbbbbbb = 2, cccccccccc = 3, dddddddddd = 4,
>>     eeeeeeeeee = 5)
>> {
>>     return(data.frame(aaaaaaaaaa, bbbbbbbbbb, cccccccccc, dddddddddd,
>>         eeeeeeeeee))
>> }
> 
> Ok, I got it. Check the keep.source option:
> 
> options("keep.source")
> 
> If it's FALSE I am getting your output and this is the problem of R, ESS
> cannot easily help you here. In my setup  keep.source is T, so I am
> getting everything ok.

It is OK from an ESS perspective only. From a R perspective, it is not.
The main problem is that R and ESS do not format code the same way, and
I'd like to use R formatting, not ESS. The 'keep.source' option is
usually set to TRUE, but is generally set to FALSE for packages (which
makes formatting of R code consistent). Using 'keep.source = TRUE' does
not format at all the code; what the user wrote is totally kept as-is.
Basically, I'd like to write code which follows the rules of R itself.
In my opinion, this is a problem of ESS, not R!

Is there really no possibility to get the R behaviour here? What I
normally do is 1) write my functions, 2) source them using 'keep.source
= FALSE' to use the R parser, and 3) paste them back in my .R/Rnw file.
But this is messy since it then conflicts with ESS style (e.g. every
time I add a new line, or hit C-M-q, the formatting gets changed back to
ESS rules)...

Thanks for your answer,
Mathieu.


> HTH,
> Vitalie.
> 
>>
>> That is, the new line simply adds 4 spaces from the left margin (not
>> from the opening parenthesis, which, I agree, would make no sense) and
>> do not start after the opening parenthesis. There is two reasons I would
>> like to have this behaviour with ESS: 1) first, it would not change the
>> formatting of my functions if I source them with the R parser, and 2) it
>> can be a real source of nightmares when there are many nested
>> parentheses, and everything gets pushed to the right.
>>
>> All the best,
>> Mathieu.
>>
>> Le 16/12/2011 06:32, Vitalie Spinu a écrit :
>>> Mathieu Basille <basille at ase-research.org> writes:
>>>
>>>> Dear ESS gurus,
>>>>
>>>> I feel like I'm really missing something... I searched heavily on the net, in
>>>> the ESS manual, on this list, without finding what I'm looking
>> for. Basically,
>>>> when I try to indent some code (with M-C-q), if a line break occurs in the
>>>> middle of parentheses or brackets, the next line will be indented to the
>> first
>>>> character after the parenthesis. How can I get rid of this, and get a
>> normal' 4
>>>> spaces indentation? (this is, I think, the behaviour of the R parser)
>>>>
>>>
>>> I am not really understanding that. You mean that
>>>
>>>
>>>     foo(arg1 = 1, arg2 = 2,
>>>         arg3 = 3)
>>>
>>> Is not what you want? and you would like:
>>>
>>>
>>>     foo(arg1 = 1, arg2 = 2,
>>>             arg3 = 3)
>>>
>>> instead?
>>>
>>> Doesn't make sense to me.
>>>
>>> Vitalie.

-- 

~$ whoami
Mathieu Basille, Post-Doc

~$ locate
Laboratoire d'Écologie Comportementale et de Conservation de la Faune
+ Centre d'Étude de la Forêt
Département de Biologie
Université Laval, Québec

~$ info
http://ase-research.org/basille

~$ fortune
``If you can't win by reason, go for volume.''
Calvin, by Bill Watterson.



More information about the ESS-help mailing list