[Rd] re quest for addition to R-int

Ben Bolker bolker at ufl.edu
Mon Dec 24 17:38:45 CET 2007


Martin Maechler <maechler <at> stat.math.ethz.ch> writes:

> 
> >>>>> "BB" == Ben Bolker <bolker <at> ufl.edu>
> >>>>>     on Sun, 23 Dec 2007 15:31:23 -0800 (PST) writes:
> 
>     BB> Bjørn-Helge Mevik wrote:
>     >> 
>     >> Ben Bolker wrote:
>     >> 
>     >>> http://cran.r-project.org/doc/manuals/R-ints.html#R-coding-standards
>     >>> 
>     >>> gives detailed advice on how to set the indentation level for
>     >>> C code to 4, but it took me a bit of poking around in the archives
>     >>> to find the
>     >>> 
>     >>> (setq ess-indent-level 4)
>     >>> 
>     >>> incantation for getting the R indentation right as well.
>     >> 
>     >> I'm confused.  Doesn't the suggested code 
>     >> 
>     >> (add-hook 'ess-mode-hook
>     >>  (lambda ()
>     >>   (ess-set-style 'C++)
>     >> ...
>     >> 
>     >> implicitly set ess-indent-level to 4?  At least for me, using the
>     >> suggested code gives indentation steps of 4 in R code.
>     >> 
>     >> -- 
>     >> Bjørn-Helge Mevik
>     >> 
>     >> ____
>     >> 
> 
>     BB> I guess, but since I was using emacs 21 I followed the
>     BB> instructions to use customization instead -- and I guess
>     BB> the customization steps don't include this hook ?
> 
> I'm confused, too, Ben.
> 
> Why exactly are you not willing to use the above (add-hook ...) ?
> 
> Is this an "unfortunate" wording of the "Writing R Ext.." manual?
> 
> Regards,
> Martin

 The current paragraph says:
   
    It is also important that code is written in a way that allows others to
understand it. This
is particularly helpful for fixing problems, and includes using self-descriptive
variable names,
commenting the code, and also formatting it properly. The R Core Team recommends
to use a
basic indentation of 4 for R and C (and most likely also Perl) code, and 2 for
documentation in
Rd format. Emacs users can implement this indentation style by putting the
following in one
of their startup files. (For GNU Emacs 20: for GNU Emacs 21 or later use
customization to set
the c-default-style to "bsd" and c-basic-offset to 4.)

  [followed by emacs code, including the ESS stuff]

  I read the paragraph above and assumed that I could (and
should) use the customization hooks in Emacs 21 rather than
putting the code in my .emacs file by hand.  In fact, I'm
a little confused; the customization recommended appears to
have set the following ...

(custom-set-variables
  ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(c-basic-offset 4)
 '(c-default-style (quote ((c-mode . "bsd") (java-mode . "java") (other . "gnu")))))

  which takes care of the C mode stuff but doesn't do anything
for ESS or Perl?

 Perhaps change the last sentence to

  (In GNU Emacs 21 or later one can instead use customization to set
the c-default-style to "bsd" and c-basic-offset to 4, although
the ESS and Perl styles still need to be set manually.)

  ?

  Ben



More information about the R-devel mailing list