Re: [R] writing several command line in R console

2003-03-04 Thread Petr Pikal
Hallo

On 4 Mar 2003 at 2:36, Vincent Stoliaroff wrote:

 
 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

Maybe looking to the manuals will be more precise than my 
answer.

+ 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?




 
 __
 [EMAIL PROTECTED] mailing list
 http://www.stat.math.ethz.ch/mailman/listinfo/r-help

CheersPetr Pikal
[EMAIL PROTECTED]
[EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] writing several command line in R console

2003-03-04 Thread Peter Dalgaard BSA
Petr Pikal [EMAIL PROTECTED] 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
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] writing several command line in R console

2003-03-03 Thread Spencer Graves
You can start the first line with (.  Then everything you write will 
NOT be syntactically complelte until you issue the closing ).  I 
learned this from Venables and Ripley, Modern Applied Statistics with S.

The + sign in front of each line is NOT something you should enter:  R 
changes its prompt to tell you that the previous line was not 
syntactically complete.

I prefer to keep my code someplace else and then transfer a complete 
function into R at one time.  See 
http://socserv.socsci.mcmaster.ca/jfox/Books/Companion/ESS/index.html;

Does this answer your questions?
Best Wishes,
Spencer Graves
Vincent Stoliaroff wrote:
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
__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help
__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] writing several command line in R console

2003-03-03 Thread Henrik Bengtsson
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: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Vincent 
 Stoliaroff
 Sent: den 4 mars 2003 13:36
 To: [EMAIL PROTECTED]
 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
 
 __
 [EMAIL PROTECTED] mailing list 
 http://www.stat.math.ethz.ch/mailman/listinfo/ r-help
 


__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] writing several command line in R console

2003-03-03 Thread Vincent Stoliaroff


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 [EMAIL PROTECTED]
To: 'Vincent Stoliaroff' [EMAIL PROTECTED], 
[EMAIL PROTECTED]
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: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Vincent
 Stoliaroff
 Sent: den 4 mars 2003 13:36
 To: [EMAIL PROTECTED]
 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

 __
 [EMAIL PROTECTED] mailing list
 http://www.stat.math.ethz.ch/mailman/listinfo/ r-help


__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help