[R] writing several command line in R console

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Mar 4 11:33:03 CET 2003


"Petr Pikal" <petr.pikal at precheza.cz> writes:


> > I would like to know how to step to the next line in the R console
> > editor without breaking the continuity of my code more clearly : if
> > for example I write a function, so far i have to write the all code
> > inside on the same line wich may become obscure as the function is
> > more and more complex. I would like to do like in the example of the
> > manuels:
> > 
> > >twosam <- function(y1, y2) {
> >     n1  <- length(y1); n2  <- length(y2)
> >     yb1 <- mean(y1);   yb2 <- mean(y2)    s1  <- var(y1);    s2  <-
> >     var(y2) s <- ((n1-1)*s1 + (n2-1)*s2)/(n1+n2-2) tst <- (yb1 -
> >     yb2)/sqrt(s2*(1/n1 + 1/n2))    tst  }

...
> 
> + is a continuity sign and means you did not finished your imput 
> and you shall continue typing your command.
> 
> But why you do not use any text ditor for writing functions and 
> than copy/paste to R command window?

I'm not sure if and how it works on Windows, but on Unix one of the
better kept secrets of the readline library is that you can embed
newlines by typing ctr-V ctr-J, e.g.

> x <- matrix(c(1,2,3,
                4,5,6,
                7,8,9), 3)

The nice thing is that it allows you to recall the entire command and
edit it (I don't think it survives being saved to the history file
though). If you have ever had to correct a typo in an expression that
has been split over 8 lines, you'll know what I mean:

up,up,up,up,up,up,up,up,RET,
up,up,up,up,up,up,up,up,RET,
up,up,up,up,up,up,up,up,RET,
up,up,up,up,up,up,up,up,fix typo,RET,
up,up,up,up,up,up,up,up,RET,
up,up,up,up,up,up,up,up,RET,
up,up,up,up,up,up,up,up,RET,
up,up,up,up,up,up,up,up,RET

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list