problem with simple if() statement

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with simple if() statement

Norman Goodacre-2
the following code apprantely, for some grand old reason, induces a syntax error:
 
  if (seq[i] = "A") m <- trans[1,]
 
  where seq is a vector and trans is a matrix. I cannot for the life of me see why this is wrong. Syntax error is:
 
  Error: syntax error in "if (seq[i] ="
 
  Sincerely,
 
  Norman Goodacre
 
 
               
---------------------------------

---------------------------------
 
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: problem with simple if() statement

Uwe Ligges
Norman Goodacre wrote:

> the following code apprantely, for some grand old reason, induces a syntax error:
>  
>   if (seq[i] = "A") m <- trans[1,]
>  
>   where seq is a vector and trans is a matrix. I cannot for the life of me see why this is wrong. Syntax error is:
>  
>   Error: syntax error in "if (seq[i] ="

I guess you mean "==" ....

Uwe Ligges


>  
>   Sincerely,
>  
>   Norman Goodacre
>  
>  
>
> ---------------------------------
>
> ---------------------------------
>  
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: problem with simple if() statement

Alexandre Aguiar
In reply to this post by Norman Goodacre-2
Em Seg 06 Fev 2006 04:22, Norman Goodacre escreveu:
>   if (seq[i] = "A") m <- trans[1,]

I'll guess that it is the use you are making of the name 'seq'. :-)
'seq' is an R function. Try some other name.


--

          Alexandre

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: problem with simple if() statement

Philippe Grosjean
In reply to this post by Norman Goodacre-2
Norman Goodacre wrote:

> the following code apprantely, for some grand old reason, induces a syntax error:
>  
>   if (seq[i] = "A") m <- trans[1,]
>  
>   where seq is a vector and trans is a matrix. I cannot for the life of me see why this is wrong. Syntax error is:
>  
>   Error: syntax error in "if (seq[i] ="
>  
>   Sincerely,
>  
>   Norman Goodacre

Please, read "An Introduction to R" provided with any version of R. The
correct syntax for an equality condition is "==", not "=", so:

 > if (seq[i] == "A") ....

Best,

Philippe Grosjean

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: problem with simple if() statement

Colin Beale
In reply to this post by Norman Goodacre-2
Norman,
you probably want:
 
  if (seq[i] == "A") m <- trans[1,]
 
hth,
Colin

>>> Norman Goodacre <[hidden email]> 06/02/2006 06:22 >>>
the following code apprantely, for some grand old reason, induces a
syntax error:
 
  if (seq[i] = "A") m <- trans[1,]
 
  where seq is a vector and trans is a matrix. I cannot for the life of
me see why this is wrong. Syntax error is:
 
  Error: syntax error in "if (seq[i] ="
 
  Sincerely,
 
  Norman Goodacre
 
 
               
---------------------------------

---------------------------------
 
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: problem with simple if() statement

justin bem
In reply to this post by Philippe Grosjean
Hi Norman !
 
I observe that R syntax is very close to C/C++ or Java

--- Philippe Grosjean <[hidden email]> a
écrit :

> Norman Goodacre wrote:
> > the following code apprantely, for some grand old
> reason, induces a syntax error:
> >  
> >   if (seq[i] = "A") m <- trans[1,]
> >  
> >   where seq is a vector and trans is a matrix. I
> cannot for the life of me see why this is wrong.
> Syntax error is:
> >  
> >   Error: syntax error in "if (seq[i] ="
> >  
> >   Sincerely,
> >  
> >   Norman Goodacre
>
> Please, read "An Introduction to R" provided with
> any version of R. The
> correct syntax for an equality condition is "==",
> not "=", so:
>
>  > if (seq[i] == "A") ....
>
> Best,
>
> Philippe Grosjean
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Turning on helpful errors in interpreter? was Re: problem with simple if() statement

Patricia Hawkins
In reply to this post by Norman Goodacre-2
Evidently, my R has some feature of error messages disabled.

>>>>> "NG" == Norman Goodacre <[hidden email]> writes:

NG> the following code apprantely, for some grand old reason, induces a syntax error:
NG>   if (seq[i] = "A") m <- trans[1,]

NG>   Error: syntax error in "if (seq[i] ="

Where Norman gets this nice error message pointing to the exact
location of the error, all I get is:

> if (1=1) 5
Error: syntax error
>

How do I turn on more-verbose error messages? Is this an environmental
issue, or a build issue?

This is a debian (ubuntu breezy) build; happens even when I run R --vanilla

R.version
         _                
platform i486-pc-linux-gnu
arch     i486            
os       linux-gnu        
system   i486, linux-gnu  
status                    
major    2                
minor    1.1              
year     2005            
month    06              
day      20              
language R                

TIA!

--
Patricia J. Hawkins
Hawkins Internet Applications
www.hawkinsia.com

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Turning on helpful errors in interpreter? was Re: problem with simple if() statement

Uwe Ligges
Patricia J. Hawkins wrote:

> Evidently, my R has some feature of error messages disabled.
>
>
>>>>>>"NG" == Norman Goodacre <[hidden email]> writes:
>
>
> NG> the following code apprantely, for some grand old reason, induces a syntax error:
> NG>   if (seq[i] = "A") m <- trans[1,]
>
> NG>   Error: syntax error in "if (seq[i] ="
>
> Where Norman gets this nice error message pointing to the exact
> location of the error, all I get is:
>
>
>>if (1=1) 5
>
> Error: syntax error
>
>
> How do I turn on more-verbose error messages? Is this an environmental
> issue, or a build issue?

It's a version issue! Please update.

Uwe Ligges


>
> This is a debian (ubuntu breezy) build; happens even when I run R --vanilla
>
> R.version
>          _                
> platform i486-pc-linux-gnu
> arch     i486            
> os       linux-gnu        
> system   i486, linux-gnu  
> status                    
> major    2                
> minor    1.1              
> year     2005            
> month    06              
> day      20              
> language R                
>
> TIA!
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html