[ESS] Yet another indentation question: indentation after parenthese
Mathieu Basille
basille at ase-research.org
Fri Dec 23 02:23:38 CET 2011
Tim,
Le 22/12/2011 14:07, Tim Hesterberg a écrit :
>>>> I just hoped that there was a way to follow what R uses internally to
> format R code.
>
> I have to throw in a caution about using R's formatting. It is often
> misleading.
> Here's one example:
I agree that R's formatting can be confusing some time, and this is a nice
example. However, my intend was not to determine the best formatting ever.
There are some guidelines out there with this specific aim, e.g. the
Google's R style guide [1] or the R coding conventions by H. Bengtsson [2],
and ESS's own style probably does not follow exactly either of them.
But given the fact that every base R code get formatted the R way, I
believe it is interesting to have the possibility to format any code the
same way! And Vitalie's function is just perfect for this, since it
directly uses the R parser...
Best,
Mathieu.
[1] https://google-styleguide.googlecode.com/svn/trunk/google-r-style.html
[2] http://www1.maths.lth.se/help/R/RCC/
>
>> as.matrix.default
> function (x, ...)
> {
> if (is.matrix(x))
> x
> else array(x, c(length(x), 1L), if (!is.null(names(x)))
> list(names(x), NULL)
> else NULL)
> }
> <environment: namespace:base>
>
> This formatting suggests that the structure is:
>
> if(condition)
> result1
> else if(condition)
> result2
> else
> result3
>
> Better would be:
>
> function (x, ...)
> {
> if (is.matrix(x))
> x
> else
> array(x, c(length(x), 1L),
> if (!is.null(names(x)))
> list(names(x), NULL)
> else
> NULL)
> }
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
--
~$ 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