[R] line breaks

Michaell Taylor pols1oh at bestweb.net
Mon Mar 18 17:09:15 CET 2002



I have a question about the function of line feeds/carriage returns in
an all linux (R, vi to write scripts) environment.  In my scripts I have
a few functions, using { or ( to wrap commands on the next line. 
Usually this is fine, but sometimes R appears confused by line wrappings
(more likely of course it is me who is confused).  I tried ';' to
explictly break the line, but no dice.

An example (partial function).


inrange _ function(v,Y,s,z,mlv,met){
	lower _ mean(v[data$yr==Y])-(var(v[data$yr==Y])^.5)
	upper _ mean(v[data$yr==Y])+(var(v[data$yr==Y])^.5)
	ML _ mlv[ML$yr==Y & ML$metcode==met]
	diff _ 0
	if (ML<lower) {diff <- lower-ML;   # tried with and without ; 
		v <<- v-diff}
	}

gives:

> inrange _ function(v,Y,s,z,mlv,met){
+ lower _ mean(v[data$yr==Y])-(var(v[data$yr==Y])^.5)
+ upper _ mean(v[data$yr==Y])+(var(v[data$yr==Y])^.5)
+ ML _ mlv[ML$yr==Y & ML$metcode==met]
+ diff _ 0
+ if (ML<lower) {diff <- lower-ML; v <<- v-diff}}
> inrange _ function(v,Y,s,z,mlv,met){
+ lower _ mean(v[data$yr==Y])-(var(v[data$yr==Y])^.5)
+ upper _ mean(v[data$yr==Y])+(var(v[data$yr==Y])^.5)
+ ML _ mlv[ML$yr==Y & ML$metcode==met]
+ diff _ 0
+ if (ML<lower) {diff <- lower-ML;
+
Display all 100 possibilities? (y or n)
ActualTen.dta         .check.R.swl          .marketFix.log.swp    
.
.
contents of directory
.
.
 runsed                test.log
check.R               marketFix.log         PreRet.tar.gz        
.runsed.swp           test.R
+ <<- v-diff}
Error: syntax error

Where: 
> inrange _ function(v,Y,s,z,mlv,met){
+ lower _ mean(v[data$yr==Y])-(var(v[data$yr==Y])^.5)
+ upper _ mean(v[data$yr==Y])+(var(v[data$yr==Y])^.5)
+ ML _ mlv[ML$yr==Y & ML$metcode==met]
+ diff _ 0
+ if (ML<lower) {diff <- lower-ML; v <<- v-diff}
+ }
>
Same line works fine??

Some fuctions in the same script work fine....ie.

>adj _ function(x,F,lastf) {
+ if (F>0) {x[x>F & x < lastf] <<- x[x>F & x < lastf]*.95}
+ if (F<0) {x[x<F & x > lastf] <<- x[x<F & x > lastf]*.95}
+ }
>

The script has never been opened in a windows machine and I would swear
that it worked last week.


Any ideas?

Michaell

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list