1 #### File showing off things that go wrong -- with R-mode
3 ## From: Robert Gentleman <rgentlem@fhcrc.org>
4 ## To: Martin Maechler <maechler@stat.math.ethz.ch>
6 ## Date: Sun, 01 Jul 2007 21:41:24 -0700
9 ## It seems that the following buglet exists (at least in what ever
10 ## version I am using)
14 foo <- function(x=a, abc = list("def", a=1,3,3), more.args, and, bla,
16 another, and, another, and bmbasd,
21 ##- when the line before a function def is a comment, and adding args,
22 ##- then new lines, when generated have a comment char at the beginning of
23 ##- the line. It is slighly annoying as I have to remove the comment char.
25 ##- If I add a blank line after the comment line, then the problem does not
27 ## and another ''anonymous'' function:
28 function(x=a, abc = list("def", a=c(1,3,3)), more.args, and, bla, blu,
30 another, and, another, and, bmbasd) {
35 ### --- Suggestion (Jenny Brian): --> Create a (defun ess-eval-multiline .)
36 ### Here is useful valid R "test code":
38 ## From 'example(plot.default)' :
42 plot(Speed, Distance, panel.first = grid(8,8),
43 pch = 0, cex = 1.2, col = "blue")
44 pp <- plot(Speed, Distance, panel.first = grid(8,8),
45 pch = 0, cex = 1.2, col = "blue")
47 panel.first = lines(lowess(Speed, Distance), lty = "dashed"),
48 pch = 0, cex = 1.2, col = "blue")
54 ### Here, the indentation is wrong:
61 indic <- ifelse(jinf+1 <= 1 & jsup >= 1,1,0)
62 E.cond <- ch*(-pbinom(jinf,ni,prb) + 1-pbinom(js.n,ni,prb)) +
63 ifelse(ni == 1, prb*indic,
64 mu*(pbinom(js.n-1,pmax(ni-1,1),prb)-
65 pbinom(jinf-1,pmax(ni-1,1),prb))) / sV -
66 ### why is the following line wrongly indented by Emacs/ESS ?
67 mu/sV*(pbinom(js.n,ni,prb) - pbinom(jinf,ni,prb))
69 indic2 <- ifelse(jinf+1 <= 1 & jsup >= 1 & ni == 2,1,0)
75 ### Here, the beginning of function is not found correctly, and hence
76 ### all "ess-*-function" (C-M-a, C-M-e, ...) fail:
79 ## It is clearly allowed to have comments here.
80 ## S version 4, and John Chambers in particular like it.
82 ## BUG: M-C-e or M-C-a fails from ``here'' --
83 ## --- effectively because of ess-beginning-of-function fails
84 ## and that really relies on finding ess-function-pattern;
85 ## i.e., ess-R-function-pattern in ~/emacs/ess/lisp/ess-cust.el
87 function(name, def = NULL, group = list(), valueClass = character(),
88 where = topenv(parent.frame()), genericFunction = NULL)
90 ## comments in here are at least kept via "source" attribute
91 if(exists(name, "package:base") &&
92 typeof(get(name, "package:base")) != "closure") {
98 ## this has one line more before 'function' than "typically:"
99 setMethod("[", signature(x = "dgTMatrix", i = "numeric", j = "missing",
101 function (x, i, j, ..., drop) { ## select rows
102 storage.mode(i) <- "integer"
103 xi <- x@i + 1:1 # 1-indexing
104 ## ...................
105 if (drop && any(nd == 1)) drop(as(x,"matrix")) else x
108 "dimnames<-.data.frame" <- function(x, value) {
110 if(!is.list(value) || length(value) != 2
111 || d[[1]] != length(value[[1]])
112 || d[[2]] != length(value[[2]]))
113 stop("invalid 'dimnames' given for data frame")
114 row.names(x) <- as.character(value[[1]]) # checks validity
115 names(x) <- as.character(value[[2]])
119 '[.foo' <- function(x, i, value)
127 '[[.bar' <- function(x, i, value)
130 y <- as.foo(x) ; y[[i]] <- value
134 "[<-.foobar" <- function(x,i,j,value) {
139 "names<-.foobar" <- function(x, value) {
140 ## just something else
144 "[<-.data.frame" <- function(x, i, j, value)
146 nA <- nargs() # value is never missing, so 3 or 4.
154 "[[<-.data.frame"<- function(x, i, j, value)
157 ## delete class: Version 3 idiom
158 ## to avoid any special methods for [[<-
168 "$<-.data.frame"<- function(x, i, value)
171 ## delete class: Version 3 idiom
172 ## to avoid any special methods for [[<-