beautifying an R package (thanks and one question)

Ramon Diaz-Uriarte ramon-diaz at teleline.es
Sat Oct 7 11:57:49 CEST 2000


Thank you very much to Martin, Rich and Andy for comments and suggestions on
how to fix ugly the appearance of R; my main problem was not indenting (that I
got right ---more or less) but spaces around operators, etc, and thus Martin's
solution seems the best one for my case.  However, I am having some problems
using it, though.

When I do M-x R-fix-miscellaneous (or M-x-R-fix-T-F) I get the error message:
"Autoloading failed to define function ess-rep-regexp".


I understood from Martin's email that I should comment the definition of
ess-rep-regexp in ess-utils.el (although that and other functions are called by
R-fix?). But to try and see what happens, and being an 
ignorant about the inner workings of ESS and (Xemacs), I used again  the
original ess-site.el file (with ESS-5.1.16), and did "make EMACS=xemacs" and
"make EMACS=xemacs install" again. Then, I didn't get the error message, but
R-fix and R-fix-misc. didn't seem to do anything.


I guess I am missing someting obvious. What is it?

Thanks,

Ramon

P.S. Note that I assumed that

> ;;;;
> ;;;; Functions & Variables  for  ``R Core Style Fixing'' of  R code.
> 
> (defun string<= (a b) (or (string= a b) (string< a b)))

should be include in ess.el. Is this correct?


P.S.2. In case it matters, I am using Linux (Suse 6.3) and have ess in:
/usr/X11R6/lib/xemacs/site-lisp/ess-5.1.16/lisp

when doing make and make install everything seems to work just fine, and ESS
seems to work fine otherwise.







On Fri, 06 Oct 2000, Martin Maechler wrote:
> >>>>> "Ramon" == Ramon Diaz-Uriarte <ramon-diaz at teleline.es> writes:
> 
>     Ramon> I wrote an R package and (because I was sloppy the
>     Ramon> first time) indentation, spacing, etc, are not what they should
>     Ramon> be (things such as always having spaces around "<-", after
>     Ramon> commas and binary operators, etc).  I was wondering if there is
>     Ramon> a way to fix up this mess (while also keeping all the comments
>     Ramon> in their current position). For instance, I love the way it
>     Ramon> looks when I source things into R, but then all comments are
>     Ramon> gone, etc.
> 
> >>>>> "Rich" == Rich Heiberger <rmh at surfer.sbm.temple.edu> writes:
> 
>     Rich> Yes, once you have installed ESS, open up your file myfile.r in emacs.
>     Rich> it will come up in ESS[S] mode.  Highlight the entire file and enter
>     Rich>         M-x indent-region
> 
>     Rich> The whole file will be indented according to the usual S
>     Rich> prettification rules.
> 
> {Good, but it's usally a doing rather too much }
> 
> 
> Additionally, for solving Ramon's problem:
> Here is 
>      M-x R-fix-miscellaneous
> that I've been using quite a few times in the past.
> 
> Would it make sense to make it available in ESS ?
> {one reason against that: it's not 100% bug free..}
> 
> 
> ;;;== NOW in ess/lisp/ess-utils.el :
> ;; (defun inside-string/comment-p (pos) ....)
> 
> ;; (defvar nuke-trailing-whitespace-p nil ...)
> 
> ;; (defun nuke-trailing-whitespace () ....)
> 
> ;; (defun ess-rep-regexp (regexp to-string &optional fixedcase literal verbose)
> ;;  ....)
> 
> ;;;== NOW in ess/lisp/essl-s.el :
> 
> ;; (defun ess-fix-comments (&optional dodefunt-query verbose) ....)
> 
> ;; (defun ess-dump-to-src (&optional dont-query verbose) ....)
> 
> (defun R-fix-T-F (&optional from quietly)
>   "Fix T/F into TRUE and FALSE --- CAUTIOUSLY"
>   (interactive "d\nP"); point and prefix (C-u)
>   (save-excursion
>     (goto-char from)
>     (ess-rep-regexp "\\(= *\\|<- *\\)T\\>" "\\1TRUE" 'fixcase nil (not quietly))
>     (goto-char from)
>     (ess-rep-regexp "\\(= *\\|<- *\\)F\\>" "\\1FALSE" 'fixcase nil(not quietly))
>     ))
> 
> ;;; The following is too dangerous: Can only have it when we have a reliable
> ;;;  (inside-string-p) :
> (defun R-fix-miscellaneous (&optional from verbose)
>   "Fix Miscellaneous R `ill-formation's."
>   (interactive "d\nP"); point and prefix (C-u)
>   (save-excursion
> 
>     ;;-- The next 4 lines:  == (R-fix-T-F) --------------------
>     (goto-char from)
>     (ess-rep-regexp "\\(= *\\|<- *\\)T\\>" "\\1TRUE" 'fix nil verbose)
>     (goto-char from)
>     (ess-rep-regexp "\\(= *\\|<- *\\)F\\>" "\\1FALSE" 'fix nil verbose)
> 
>     (goto-char from) (ess-rep-regexp " *_ *" " <- " nil 'literal verbose)
> 
>     ;; -- ensure space around  "<-"  ---- but only replace if necessary:
>     (goto-char from)(ess-rep-regexp "\\([^ \t\n]\\)<-" "\\1 <-" nil nil verbose)
>     (goto-char from)(ess-rep-regexp "<-\\([^ \t\n]\\)" "<- \\1" nil nil verbose)
>     ;; -- ensure space around  "<" (but not "<-" / "<=")  and ">" (not ">=") :
>     (goto-char from);; --> " <", care with "->":
>     (ess-rep-regexp "\\([^- \t\n]\\)\\([<>]\\)" "\\1 \\2" nil nil verbose)
>     ;; ">" -> "> " , for "<", don't split "<-":
>     (goto-char from)
>     (ess-rep-regexp "\\(>=?\\)\\([^ \t\n]\\)" "\\1 \\2" nil nil verbose)
>     (goto-char from)
>     (ess-rep-regexp "\\(<=?\\)\\([^- \t\n]\\)" "\\1 \\2" nil nil t);; !
>     ;; -- ensure space around "=", "==", "!=" :
>     (goto-char from) ;; --> " ="
>     (ess-rep-regexp "\\([^=!<> ]\\)\\([=!]?\\)=" "\\1 \\2=" nil nil verbose)
>     (goto-char from) (ess-rep-regexp "=\\([^= ]\\)" "= \\1" nil nil verbose)
> 
>     (goto-char from) ;; add a space between "{" and a subsequent wordchar:
>     (ess-rep-regexp "\\([()]\\){\\([A-Za-z()]\\)" "{ \\1" 'fix nil verbose)
>     (goto-char from) ;; add a space between "}" and a preceding wordchar:
>     (ess-rep-regexp "\\([A-Za-z0-9()]\\)}" "\\1 }" 'fix nil verbose)
> 
>     ;; add a newline and indent before a "}"
>     ;; --- IFF there's NO "{" or "#" AND some NON-white text on the same line:
>     ;;D (if verbose (message "\t R-fix-misc..: Hard.. '}'"))
>     (goto-char from)
>     (ess-rep-regexp "^\\([^#{\n]*[^#{ \t\n]+[ \t]*\\)}[ \t]*$"
> 		     "\\1\n}" 'fix nil verbose)
>     ))
-- 
Ramón Díaz-Uriarte
Triana 47
28016 Madrid
Spain

email:ramon-diaz at teleline.es
Phone: +-34-918-513-966
       +-34-657-186-407	







-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
ess-help mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: ess-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the ESS-help mailing list