[R] Indentation in R code

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Sep 25 19:40:45 CEST 2005


Seth Falcon <sfalcon at fhcrc.org> writes:

> On 24 Sep 2005, goran.brostrom at gmail.com wrote:
> 
> > I am using emacs-21.3 when writing R functions on Linux debian, and
> > I am trying to follow the advice i R-exts.pdf (2.1.1) regarding
> > indentation. That is, I set 'c-default-style' to "bsd" and
> > 'c-basic-offset' to 4. However, while this gives me the intended
> > indentation in C code, it doesn't change the behavior in R code; I
> > still get an indentation of size 2. This is my .emacs file after
> > customization:
> >
> > (require 'ess-site)
> > (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 "bsd"))
> > (custom-set-faces
> > ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
> > ;; Your init file should contain only one such instance.
> > )
> 
> Not sure if this is the best way, but I have the following after
> loading ess-site:
> 
> (setq ess-indent-level 4)
> 

I have (I believe it stems from Martin M. originally):

(add-hook 'c-mode-hook '(lambda()
                          (c-set-style "stroustrup")))
(add-hook 'ess-mode-hook
      '(lambda()
         (if (or (string< ess-version "5.0")
                 (string= ess-version "5.0"))
             (ess-set-style 'C++)
           (ess-set-style 'C++ 'quiet))

         (add-hook 'local-write-file-hooks
                   '(lambda()
                      (delete-trailing-whitespace)
                      ))
         ))


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list