[R] writing several command line in R console
Vincent Stoliaroff
vsensae at hotmail.com
Tue Mar 4 04:36:50 CET 2003
Thanks to all
1) OK for the "+" sign and the problem of syntactelly unbreaking when you
open a { or a (
2) Thanks for the advise to use another editor for the functions. And then
the source() function. I tried it succesfully
Long life to R!
>From: "Henrik Bengtsson" <hb at maths.lth.se>
>To: "'Vincent Stoliaroff'" <vsensae at hotmail.com>,
><r-help at stat.math.ethz.ch>
>Subject: RE: [R] writing several command line in R console
>Date: Tue, 4 Mar 2003 14:04:13 +1100
>
>The R prompt should be though of as a one line editor or rather one
>expression editor. You can not "step" between lines etc while editing an
>expression. The "+" in front of each row placed there by R indicating
>that even if you have typed ENTER the expression is not finished and
>that R expect you to close it (normally by closing brackets, parentesis
>etc). The "+" is just an indicator and will not be included in your
>expression.
>
>What you really want to do when you create functions etc is to write the
>up in an external text editor, save them with the extension *.R, e.g.
>"twosam.R", and the use source to read the function in to R, i.e.
>
> > source("twosam.R")
>
>Make sure to save your twosam.R file as *text*. If you're using Windows
>you can use Notepad to do this. Also, you have to save the file in the
>working directory of R. You can find the current working directory of R
>by
>
> > getwd()
>
>Alternatively, you'll have to specify the full path to the file when
>using source
>
> > source("C:/My Documents/hb/twosam.R")
>
>Hope this helps!
>
>Henrik Bengtsson
>
> > -----Original Message-----
> > From: r-help-admin at stat.math.ethz.ch
> > [mailto:r-help-admin at stat.math.ethz.ch] On Behalf Of Vincent
> > Stoliaroff
> > Sent: den 4 mars 2003 13:36
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] writing several command line in R console
> >
> >
> >
> > Hi R lovers
> >
> > 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 }
> >
> >
> > all I can do is something like that:
> >
> > >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 }
> >
> > with the sign "+" in front of each line
> > What does this sign mean? and how could I solve my problems Thanks
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > http://www.stat.math.ethz.ch/mailman/listinfo/> r-help
> >
> >
More information about the R-help
mailing list