Quantcast

Unreasonable syntax error

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Unreasonable syntax error

james198877
PSC.r

Hi all,

I just wrote a program in R by editing it in Microsoft Word and then pasting into the text editor of R. The above is the file.

And below is what the console complains.... Why doesn't it recognise 'r'??

I have to mention that at least when I typed this first several lines into the console, the first error didn't appear. I don't try the next errors as there would be too many lines to type...I'm not sure if this is something about Word

lastsave.txt

Thanks a lot for your help!!!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Unreasonable syntax error

Ray Brownrigg-2
On Tue, 21 Jun 2011, james198877 wrote:
> http://r.789695.n4.nabble.com/file/n3612530/PSC.r PSC.r
>
> Hi all,
>
> I just wrote a program in R by editing it in Microsoft Word and then
> pasting into the text editor of R. The above is the file.
>
> And below is what the console complains.... Why doesn't it recognise 'r'??

I don't see 'r' at all.  It doesn't recognise s.

You have strange (16-bit?) characters in your .r file.

Note in your output:
 NdeTirage<-1  # NdeTirage d?signe le nombre de tirages
> Longueur<-40  # L'exp?rience s'?tale sur 40 semaines
>
> # Ecriture de la matrice des param?tres
> par<-function(N){
+   s<- array(0,c(4,8,N));
+   for( k in 1:N){
+      s[1,3,k]<- (0.1) * runif(1)+ 0.1;
+      s[1,1,k]<- (0.02) *  runif(1)+ 0.98 ¨C s[1,3,k];
                                                             ^^
>      s[1,5,k]<- (0.04) * runif(1) + 0.04;
Error in s[1, 5, k] <- (0.04) * runif(1) + 0.04 : object 's' not found

The "¨C"  (which I guess is a 'dash' rather than a 'minus') is not recognised, and seems
to 'complete' the function definition (the "+'s stop appearing in column 1), but s is only
defined inside the function.  

>
> I have to mention that at least when I typed this first several lines into
> the console, the first error didn't appear. I don't try the next errors as
> there would be too many lines to type...I'm not sure if this is something
> about Word
>
> http://r.789695.n4.nabble.com/file/n3612530/lastsave.txt lastsave.txt
>
> Thanks a lot for your help!!!
>
Why use Word for a text file when Notepad would do the job (better)?

Ray Brownrigg

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Unreasonable syntax error

Bill.Venables
In reply to this post by james198877
The advice is always NOT to use Microsoft Word to edit an R file.  That stuff is poisonous.  Microsoft word, typical of all Microsoft software, does not do what you tell it to do but helpfully does what it thinks you meant to ask it to do but were too dumb to do so.

Even notepad, gawdelpus, would be better.

When I look at your script the first sign of trouble I see is:

Error: unexpected input in:
"     s[1,3,k]<- (0.1) * runif(1)+ 0.1;
     s[1,1,k]<- (0.02) *  runif(1)+ 0.98 ¨"

which is the spurious character Microsoft word has helpfully inserted to make it all look nice.  It's downhill all the way from there.

(R does not expect Microsoft Word, just as "nobody expects the Spanish Inquisition".  See http://www.youtube.com/watch?v=CSe38dzJYkY).

Bill Venables.

 
 

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of james198877
Sent: Tuesday, 21 June 2011 7:13 AM
To: [hidden email]
Subject: [R] Unreasonable syntax error

http://r.789695.n4.nabble.com/file/n3612530/PSC.r PSC.r

Hi all,

I just wrote a program in R by editing it in Microsoft Word and then pasting
into the text editor of R. The above is the file.

And below is what the console complains.... Why doesn't it recognise 'r'??

I have to mention that at least when I typed this first several lines into
the console, the first error didn't appear. I don't try the next errors as
there would be too many lines to type...I'm not sure if this is something
about Word

http://r.789695.n4.nabble.com/file/n3612530/lastsave.txt lastsave.txt

Thanks a lot for your help!!!

--
View this message in context: http://r.789695.n4.nabble.com/Unreasonable-syntax-error-tp3612530p3612530.html
Sent from the R help mailing list archive at Nabble.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
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Unreasonable syntax error

ted.harding-3
How long can a fortune be? Bill's response is fortune-worthy
in its entirety!

I would intensify his advice to "NOT to use Microsoft Word."
Note the Full Stop.

I will spare people the full catalogue of misfortunes I have
observed, but feel inclined to cite the case of someone to
whom I once sent a PostScript file, who, naively, opened it
in Word which, helpfully (as Bill emphasises), was in
"Autosave" mode. Within a few seconds the file was scrambled
beyond recovery.

Best wishes to all,
Ted.

On 20-Jun-11 22:47:49, [hidden email] wrote:

> The advice is always NOT to use Microsoft Word to edit an R file.
> That stuff is poisonous.  Microsoft word, typical of all Microsoft
> software, does not do what you tell it to do but helpfully does
> what it thinks you meant to ask it to do but were too dumb to do so.
>
> Even notepad, gawdelpus, would be better.
>
> When I look at your script the first sign of trouble I see is:
>
> Error: unexpected input in:
> "     s[1,3,k]<- (0.1) * runif(1)+ 0.1;
>      s[1,1,k]<- (0.02) *  runif(1)+ 0.98 ¨"
>
> which is the spurious character Microsoft word has helpfully inserted
> to make it all look nice.  It's downhill all the way from there.
>
> (R does not expect Microsoft Word, just as "nobody expects the Spanish
> Inquisition".  See http://www.youtube.com/watch?v=CSe38dzJYkY).
>
> Bill Venables.
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of james198877
> Sent: Tuesday, 21 June 2011 7:13 AM
> To: [hidden email]
> Subject: [R] Unreasonable syntax error
>
> http://r.789695.n4.nabble.com/file/n3612530/PSC.r PSC.r
>
> Hi all,
>
> I just wrote a program in R by editing it in Microsoft Word and then
> pasting
> into the text editor of R. The above is the file.
>
> And below is what the console complains.... Why doesn't it recognise
> 'r'??
>
> I have to mention that at least when I typed this first several lines
> into
> the console, the first error didn't appear. I don't try the next errors
> as
> there would be too many lines to type...I'm not sure if this is
> something
> about Word
>
> http://r.789695.n4.nabble.com/file/n3612530/lastsave.txt lastsave.txt
>
> Thanks a lot for your help!!!

--------------------------------------------------------------------
E-Mail: (Ted Harding) <[hidden email]>
Fax-to-email: +44 (0)870 094 0861
Date: 21-Jun-11                                       Time: 08:25:11
------------------------------ XFMail ------------------------------

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Unreasonable syntax error

Daniel Malter
In reply to this post by james198877
I find this sign in the code multiple times: ¨C; I replaced those with *; there is also a MS-Word flexible hyphenation sign in there somewhere, probably standing for a minus sign. Other than that, there are a couple of output calls within loops that do not do anything anyway, but which seem to be misplaced in those loops. The below code, removing those unnecessary calls and MS symbols gives you code that runs through smoothly:

NdeTirage<-1  
Longueur<-40


par<-function(N){
  s<- array(0,c(4,8,N));
  for( k in 1:N){
     s[1,3,k]<- (0.1) * runif(1)+ 0.1; }
     s
}
#
# Matrice des param?tres
para<-par(NdeTirage); #para<-(i,n?param?tre,n?tirage)

# Donn?es sur i (i(p,t) o? t est le num?ro de la semaine)
# p<-1 -> Plowed 2006 ; p<-2 -> Plowed 2007 ; p<-3 -> Unplowed 2006 ; p<-4 -> Unplowed 2007
i <- array(1, c(4,Longueur));
i[1,1]<-2;
i[1,2]<-1;
i[1,3]<-2;
i[1,32]<-1; #p<-1 -> Plowed 2006  
for (m in 4:11)
    i[1,m]<-1;
NdeTirage<-1  # NdeTirage d?signe le nombre de tirages
Longueur<-40  # L'exp?rience s'?tale sur 40 semaines

# Ecriture de la matrice des param?tres
par<-function(N){
  s<- array(0,c(4,8,N));
  for( k in 1:N){
     s[1,3,k]<- (0.1) * runif(1)+ 0.1;
     s[1,1,k]<- (0.02) *  runif(1)+ 0.98 * s[1,3,k];
     s[1,5,k]<- (0.04) * runif(1) + 0.04;
     s[1,4,k]<- (0.01)* runif(1) + 0.99 * s[1,5,k];
     s[1,7,k]<- (0.26)* runif(1)+ 0.14;
     s[1,6,k]<- (0.01) * runif(1) + 0.99 * s[1,7,k];
     s[1,8,k]<- (0.01)* runif(1) + 0.99; s[1,2,k]<- (1.31)* runif(1) + 0.19;
     s[2,3,k]<- (s[1,3,k]-max(0.8-s[1,1,k],0))*runif(1)+max(0.8-s[1,1,k],0);
     s[2,1,k]<- (s[1,1,k]-(0.8-s[2,3,k]))*runif(1)+(0.8-s[2,3,k]);
     s[2,5,k]<- (s[1,5,k]-max(0.4-s[1,4,k],0))*runif(1)+max(0.4-s[1,4,k],0);
     s[2,4,k]<- (s[1,4,k]-(0.4-s[2,5,k]))*runif(1)+(0.4-s[2,5,k]);
     s[2,7,k]<- (s[1,7,k]-max(0.7-s[1,6,k],0))*runif(1)+max(0.7-s[1,6,k],0);
     s[2,6,k]<- (s[1,6,k]-(0.7-s[2,7,k]))*runif(1)+(0.7-s[2,7,k]);
     s[2,8,k]<- (s[1,8,k]- 0.7)* runif(1) + 0.7;
     s[2,2,k]<- s[1,2,k]* runif(1);
     s[3,3,k]<- (s[2,3,k]-max(0.8-s[2,1,k],0))*runif(1)+max(0.8-s[2,1,k],0);
     s[3,1,k]<- (s[2,1,k]-(0.8-s[3,3,k]))*runif(1)+(0.8-s[3,3,k]);
     s[3,5,k]<- (s[2,5,k]-max(0.4-s[2,4,k],0))*runif(1)+max(0.4-s[2,4,k],0);
     s[3,4,k]<- (s[2,4,k]-(0.4-s[3,5,k]))*runif(1)+(0.4-s[3,5,k]);
     s[3,7,k]<- (s[2,7,k]-max(0.7-s[2,6,k],0))*runif(1)+max(0.7-s[2,6,k],0);
     s[3,6,k]<- (s[2,6,k]-(0.7-s[3,7,k]))*runif(1)+(0.7-s[3,7,k]);
     s[3,8,k]<- (s[2,8,k]- 0.7)* runif(1) + 0.7;
     s[3,2,k]<- s[2,2,k]* runif(1);
     s[4,3,k]<- (s[3,3,k]-max(0.8-s[3,1,k],0))*runif(1)+max(0.8-s[3,1,k],0);
     s[4,1,k]<- (s[3,1,k]-(0.8-s[4,3,k]))*runif(1)+(0.8-s[4,3,k]);
     s[4,5,k]<- (s[3,5,k]-max(0.4-s[3,4,k],0))*runif(1)+max(0.4-s[3,4,k],0);
     s[4,4,k]<- (s[3,4,k]-(0.4-s[4,5,k]))*runif(1)+(0.4-s[4,5,k]);
     s[4,7,k]<- (s[3,7,k]-max(0.7-s[3,6,k],0))*runif(1)+max(0.7-s[3,6,k],0);
     s[4,6,k]<- (s[3,6,k]-(0.7-s[4,7,k]))*runif(1)+(0.7-s[4,7,k]);
     s[4,8,k]<- (s[3,8,k]- 0.7)* runif(1) + 0.7;
     s[4,2,k]<- s[3,2,k]* runif(1);  }
     s}
#
# Matrice des param?tres
para<-par(NdeTirage); #para<-(i,n?param?tre,n?tirage)

# Donn?es sur i (i(p,t) o? t est le num?ro de la semaine)
# p<-1 -> Plowed 2006 ; p<-2 -> Plowed 2007 ; p<-3 -> Unplowed 2006 ; p<-4 -> Unplowed 2007
i <- array(1, c(4,Longueur));
i[1,1]<-2;
i[1,2]<-1;
i[1,3]<-2;
i[1,32]<-1; #p<-1 -> Plowed 2006  
for (m in 4:11)
    i[1,m]<-1;

for( m in 12:31)
    i[1,m]<-3;

for( m in 33:38)
    i[1,m]<-2;

for (m in 1:3) # p<-2 ->Plowed 2007
    i[2,m]<-2;

for (m in 30:40)
    i[2,m]<-2;

for (m in 4:29)
    i[2,m]<-1;

i[3,1]<-2;
i[3,3]<-2;
i[3,4]<-2;
i[3,33]<-2;
i[3,34]<-2;
i[3,36]<-2;
i[3,37]<-2;
i[3,38]<-2;#p<-3 -> Unplowed 2006
i[3,2]<-1;
for (m in 5:14)
    i[3,m]<-1;

for (m in 15:22)
    i[3,m]<-3;

for (m in 23:25)
    i[3,m]<-1;

for (m in 26:29)
    i[3,m]<-3;

for (m in 30:32)
    i[3,m]<-1;

i[3,35]<-1;

for (m in 1:3)#p<-4 -> Unplowed 2007
    i[4,m]<-2;

for (m in 4:31)
    i[4,m]<-1;

for (m in 32:40)
    i[4,m]<-2;

#

# Ecriture des autres param?tres

para2<- array(0,c(4,8, NdeTirage, 40));

# On va donner les valeurs de CS et CJcs
for ( k in 1:NdeTirage){
  para2[1,6,k,1]<- 0.7 *13* para[2,3,k]; para2[2,6,k,1]<- 0.7 *13* para[2,3,k]; para2[3,6,k,1]<- 9.5 *13* para[2,3,k]; para2[4,6,k,1]<- 9.5 *13* para[2,3,k];

for ( p in 1:4){
    for (t in 1:12){
      para2[p,6,k,t+1]<- para[i[p,t],1,k]*para2[p,6,k,t];
    }
    para2[p,5,k,13]<- para[i[p,13],3,k];
    for (t in 13:39){
      para2[p,5,k,t+1]<- para[i[p,t+1],3,k];
      para2[p,6,k,t+1]<- para[i[p,t],1,k]*para2[p,6,k,t] - para2[p,5,k,t-1] *para2[p,6,k,t-1];    }}}
#      



# On renvoie para2 (t+1) en prenant comme arguments pat<- para2(t) et rt<-resultat(t)
par2 <-function(t, pat, rt){
  g<- array(0,c(4,8,NdeTirage));
  for ( p in 1:4){
    for( k in 1:NdeTirage){
      if (t==1){
        if (i[p,1]<3){
          g[p,1,k]<- 0;
          g[p,2,k]<- 0;
        }else{
          g[p,1,k]<- para[i[p,1],6,k]*rt[p,k,3]+ para[i[p,1],5,k]* rt[p,k,2];
          g[p,2,k]<- para[i[p,1],8,k]*rt[p,k,4]+ para[i[p,1],7,k]* rt[p,k,3];
        }
        g[p,7,k]<- para[1,6,k]*pat[p,7,k]+ g[p,1,k]-g[p,3,k];
        g[p,8,k]<- para[1,8,k]*pat[p,8,k]+ g[p,2,k]-g[p,4,k];
        g[p,6,k]<- para[i[p,1],1,k]*pat[p,6,k];
      }else{
        if (i[p,t]<3){
          g[p,1,k]<- 0;
          g[p,2,k]<- 0;
          if (i[p,t-1]>3){
            g[p,3,k]<- pat[p,7,k]* para[1,6,k];
            g[p,4,k]<- pat[p,8,k]* para[1,8,k];
          }else{
            g[p,3,k]<-0;
            g[p,4,k]<-0;
          }
        }else{
          g[p,1,k]<- para[i[p,t],6,k]*rt[p,k,3]+ para[i[p,t],5,k]* rt[p,k,2];
          g[p,2,k]<- para[i[p,t],8,k]*rt[p,k,4]+ para[i[p,t],7,k]* rt[p,k,3];
          g[p,3,k]<-0;
          g[p,4,k]<-0;
        }
        g[p,7,k]<- para[1,6,k]*pat[p,7,k]+ g[p,1,k]-g[p,3,k];
        g[p,8,k]<- para[1,8,k]*pat[p,8,k]+ g[p,2,k]-g[p,4,k];
      }
    }
  }
}
#


# On veut trouver le vecteur final en fonction de t
 
resultat<-array(0,c(4, NdeTirage, Longueur, 4)); #Initialisation de resultat o? resultat est le vecteur final. resultat(p,n?tirage,t,n?variable) , variables<- C,J,S,A

# On rentre les valeurs initiales
for (k in 1:NdeTirage){
  resultat[3,k,1,2]<- 43.13;
  resultat[3,k,1,3]<- 10.63;
  resultat[3,k,1,4]<- 3.75;
  resultat[4,k,1,2]<- 55.005;
  resultat[4,k,1,3]<- 1.88;
  resultat[4,k,1,4]<- 7.5;
  resultat[1,k,1,2]<- 11.25;
  resultat[1,k,1,3]<- 0;
  resultat[1,k,1,4]<- 0;
  resultat[2,k,1,2]<- 3.125;
  resultat[2,k,1,3]<- 0;
  resultat[2,k,1,4]<- 1.88;
}

# Ici on veut resultat (t+1) en fonction de resultat (t) et des param?tres ? t
# la fonction renvoie resultat (t+1) en  prenant comme arguments
ff<-function(t, rt, pat){
  y<- array(0, c(4, NdeTirage, 4));
  for (p in 1:4){     for ( k in 1:NdeTirage ){       y[p,k,1]<- para[i[p,t],1,k] * rt[p,k,1]+ para[i[p,t],2,k]* rt[p,k,4];      y[p,k,2]<- para[i[p,t],3,k] * rt[p,k,1]+ para[i[p,t],4,k]* rt[p,k,2] + pat[p,5,k]*pat[p,6,k];      y[p,k,3]<- para[i[p,t],5,k] * rt[p,k,2]+ para[i[p,t],6,k]* rt[p,k,3] *pat[p,1,k] + pat[p,3,k];      y[p,k,4]<- para[i[p,t],7,k] * rt[p,k,3]+ para[i[p,t],8,k]* rt[p,k,4]- pat[p,2,k] + pat[p,4,k];      if(y[p,k,1]<0) y[p,k,1]<-0;       if(y[p,k,2]<0) y[p,k,2] <- 0;       if(y[p,k,3]<0) y[p,k,3] <- 0;       if(y[p,k,4]<0) y[p,k,4] <- 0; }}}
#

# On calcule maintenant resultat(t) et para2(t) pour tout t

for ( t in 1:39){
    resultat [,,t+1,]  <-  ff(t,resultat[ , ,t,],para2 [ , , , t]);
    para2 [ , , ,t+1]  <-  par2(t, para2 [ , , ,t], resultat[ , ,t, ]);
}


#On fait maintenant la moyenne des r?sultats
resultatfinal<- array(0, c( 4, Longueur, 4 ))
for (p in 1:4){
  for (t in 1:40){
    for (n in 1:4){
      somme<-0;
      for (k in 1:NdeTirage){
        somme<- somme+ resultat[p,k,t,n];
      }
      resultatfinal[p,t,n]<- somme/NdeTirage;
    }
  }
}
#

 


#On va maintenant construire les graphiques

#En vert: 2007 , en bleu: 2006

# Juveniles pour "plowed plots"
x1<-seq(1,40)
plot(x1, resultatfinal[1, ,2])
plot(x1, resultatfinal[2, ,2])


# Sous-adultes pour "plowed plots"
plot(x1, resultatfinal[1, ,3])
plot(x1, resultatfinal[2, ,3])


# Adultes pour "plowed plots"
plot(x1, resultatfinal[1, ,4])
plot(x1, resultatfinal[2, ,4])

# Juveniles pour "unplowed plots"
plot(x1, resultatfinal[3, ,2])
plot(x1, resultatfinal[4, ,2])

# Sous-adultes pour "unplowed plots"
plot(x1, resultatfinal[3, ,3])
plot(x1, resultatfinal[4, ,3])


# Adultes pour "unplowed plots"
plot(x1, resultatfinal[3, ,4])
plot(x1, resultatfinal[4, ,4])

#




for( m in 12:31)
    i[1,m]<-3;

for( m in 33:38)
    i[1,m]<-2;

for (m in 1:3) # p<-2 ->Plowed 2007
    i[2,m]<-2;

for (m in 30:40)
    i[2,m]<-2;

for (m in 4:29)
    i[2,m]<-1;

i[3,1]<-2;
i[3,3]<-2;
i[3,4]<-2;
i[3,33]<-2;
i[3,34]<-2;
i[3,36]<-2;
i[3,37]<-2;
i[3,38]<-2;#p<-3 -> Unplowed 2006
i[3,2]<-1;
for (m in 5:14)
    i[3,m]<-1;

for (m in 15:22)
    i[3,m]<-3;

for (m in 23:25)
    i[3,m]<-1;

for (m in 26:29)
    i[3,m]<-3;

for (m in 30:32)
    i[3,m]<-1;

i[3,35]<-1;

for (m in 1:3)#p<-4 -> Unplowed 2007
    i[4,m]<-2;

for (m in 4:31)
    i[4,m]<-1;

for (m in 32:40)
    i[4,m]<-2;

#

# Ecriture des autres param?tres

para2<- array(0,c(4,8, NdeTirage, 40));

# On va donner les valeurs de CS et CJcs
for ( k in 1:NdeTirage){
  para2[1,6,k,1]<- 0.7 *13* para[2,3,k]; para2[2,6,k,1]<- 0.7 *13* para[2,3,k]; para2[3,6,k,1]<- 9.5 *13* para[2,3,k]; para2[4,6,k,1]<- 9.5 *13* para[2,3,k];

for ( p in 1:4){
    for (t in 1:12){
      para2[p,6,k,t+1]<- para[i[p,t],1,k]*para2[p,6,k,t];
    }
    para2[p,5,k,13]<- para[i[p,13],3,k];
    for (t in 13:39){
      para2[p,5,k,t+1]<- para[i[p,t+1],3,k];
      para2[p,6,k,t+1]<- para[i[p,t],1,k]*para2[p,6,k,t] - para2[p,5,k,t-1] *para2[p,6,k,t-1];    }}}
#      



# On renvoie para2 (t+1) en prenant comme arguments pat<- para2(t) et rt<-resultat(t)
par2 <-function(t, pat, rt){
  g<- array(0,c(4,8,NdeTirage));
  for ( p in 1:4){
    for( k in 1:NdeTirage){
      if (t==1){
        if (i[p,1]<3){
          g[p,1,k]<- 0;
          g[p,2,k]<- 0;
        }else{
          g[p,1,k]<- para[i[p,1],6,k]*rt[p,k,3]+ para[i[p,1],5,k]* rt[p,k,2];
          g[p,2,k]<- para[i[p,1],8,k]*rt[p,k,4]+ para[i[p,1],7,k]* rt[p,k,3];
        }
        g[p,7,k]<- para[1,6,k]*pat[p,7,k]+ g[p,1,k]-g[p,3,k];
        g[p,8,k]<- para[1,8,k]*pat[p,8,k]+ g[p,2,k]-g[p,4,k];
        g[p,6,k]<- para[i[p,1],1,k]*pat[p,6,k];
      }else{
        if (i[p,t]<3){
          g[p,1,k]<- 0;
          g[p,2,k]<- 0;
          if (i[p,t-1]>3){
            g[p,3,k]<- pat[p,7,k]* para[1,6,k];
            g[p,4,k]<- pat[p,8,k]* para[1,8,k];
          }else{
            g[p,3,k]<-0;
            g[p,4,k]<-0;
          }
        }else{
          g[p,1,k]<- para[i[p,t],6,k]*rt[p,k,3]+ para[i[p,t],5,k]* rt[p,k,2];
          g[p,2,k]<- para[i[p,t],8,k]*rt[p,k,4]+ para[i[p,t],7,k]* rt[p,k,3];
          g[p,3,k]<-0;
          g[p,4,k]<-0;
        }
        g[p,7,k]<- para[1,6,k]*pat[p,7,k]+ g[p,1,k]-g[p,3,k];
        g[p,8,k]<- para[1,8,k]*pat[p,8,k]+ g[p,2,k]-g[p,4,k];
      }
    }
  }
}
#


# On veut trouver le vecteur final en fonction de t
 
resultat<-array(0,c(4, NdeTirage, Longueur, 4)); #Initialisation de resultat o? resultat est le vecteur final. resultat(p,n?tirage,t,n?variable) , variables<- C,J,S,A

# On rentre les valeurs initiales
for (k in 1:NdeTirage){
  resultat[3,k,1,2]<- 43.13;
  resultat[3,k,1,3]<- 10.63;
  resultat[3,k,1,4]<- 3.75;
  resultat[4,k,1,2]<- 55.005;
  resultat[4,k,1,3]<- 1.88;
  resultat[4,k,1,4]<- 7.5;
  resultat[1,k,1,2]<- 11.25;
  resultat[1,k,1,3]<- 0;
  resultat[1,k,1,4]<- 0;
  resultat[2,k,1,2]<- 3.125;
  resultat[2,k,1,3]<- 0;
  resultat[2,k,1,4]<- 1.88;
}

# Ici on veut resultat (t+1) en fonction de resultat (t) et des param?tres ? t
# la fonction renvoie resultat (t+1) en  prenant comme arguments
ff<-function(t, rt, pat){
  y<- array(0, c(4, NdeTirage, 4));
  for (p in 1:4){     for ( k in 1:NdeTirage ){       y[p,k,1]<- para[i[p,t],1,k] * rt[p,k,1]+ para[i[p,t],2,k]* rt[p,k,4];      y[p,k,2]<- para[i[p,t],3,k] * rt[p,k,1]+ para[i[p,t],4,k]* rt[p,k,2] + pat[p,5,k]*pat[p,6,k];      y[p,k,3]<- para[i[p,t],5,k] * rt[p,k,2]+ para[i[p,t],6,k]* rt[p,k,3] *pat[p,1,k] + pat[p,3,k];      y[p,k,4]<- para[i[p,t],7,k] * rt[p,k,3]+ para[i[p,t],8,k]* rt[p,k,4]- pat[p,2,k] + pat[p,4,k];      if(y[p,k,1]<0) y[p,k,1]<-0;       if(y[p,k,2]<0) y[p,k,2] <- 0;       if(y[p,k,3]<0) y[p,k,3] <- 0;       if(y[p,k,4]<0) y[p,k,4] <- 0; }}}
#

# On calcule maintenant resultat(t) et para2(t) pour tout t

for ( t in 1:39){
    resultat [,,t+1,]  <-  ff(t,resultat[ , ,t,],para2 [ , , , t]);
    para2 [ , , ,t+1]  <-  par2(t, para2 [ , , ,t], resultat[ , ,t, ]);
}


#On fait maintenant la moyenne des r?sultats
resultatfinal<- array(0, c( 4, Longueur, 4 ))
for (p in 1:4){
  for (t in 1:40){
    for (n in 1:4){
      somme<-0;
      for (k in 1:NdeTirage){
        somme<- somme+ resultat[p,k,t,n];
      }
      resultatfinal[p,t,n]<- somme/NdeTirage;
    }
  }
}
#

 


#On va maintenant construire les graphiques

#En vert: 2007 , en bleu: 2006

# Juveniles pour "plowed plots"
x1<-seq(1,40)
plot(x1, resultatfinal[1, ,2])
plot(x1, resultatfinal[2, ,2])


# Sous-adultes pour "plowed plots"
plot(x1, resultatfinal[1, ,3])
plot(x1, resultatfinal[2, ,3])


# Adultes pour "plowed plots"
plot(x1, resultatfinal[1, ,4])
plot(x1, resultatfinal[2, ,4])

# Juveniles pour "unplowed plots"
plot(x1, resultatfinal[3, ,2])
plot(x1, resultatfinal[4, ,2])

# Sous-adultes pour "unplowed plots"
plot(x1, resultatfinal[3, ,3])
plot(x1, resultatfinal[4, ,3])


# Adultes pour "unplowed plots"
plot(x1, resultatfinal[3, ,4])
plot(x1, resultatfinal[4, ,4])

#












james198877 wrote
PSC.r

Hi all,

I just wrote a program in R by editing it in Microsoft Word and then pasting into the text editor of R. The above is the file.

And below is what the console complains.... Why doesn't it recognise 'r'??

I have to mention that at least when I typed this first several lines into the console, the first error didn't appear. I don't try the next errors as there would be too many lines to type...I'm not sure if this is something about Word

lastsave.txt

Thanks a lot for your help!!!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Unreasonable syntax error

Greg Snow-2
In reply to this post by ted.harding-3
I second the fortune nomination, probably the 1st paragraph is sufficient for a fortune.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
801.408.8111


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Ted Harding
> Sent: Tuesday, June 21, 2011 1:25 AM
> To: [hidden email]
> Subject: Re: [R] Unreasonable syntax error
>
> How long can a fortune be? Bill's response is fortune-worthy
> in its entirety!
>
> I would intensify his advice to "NOT to use Microsoft Word."
> Note the Full Stop.
>
> I will spare people the full catalogue of misfortunes I have
> observed, but feel inclined to cite the case of someone to
> whom I once sent a PostScript file, who, naively, opened it
> in Word which, helpfully (as Bill emphasises), was in
> "Autosave" mode. Within a few seconds the file was scrambled
> beyond recovery.
>
> Best wishes to all,
> Ted.
>
> On 20-Jun-11 22:47:49, [hidden email] wrote:
> > The advice is always NOT to use Microsoft Word to edit an R file.
> > That stuff is poisonous.  Microsoft word, typical of all Microsoft
> > software, does not do what you tell it to do but helpfully does
> > what it thinks you meant to ask it to do but were too dumb to do so.
> >
> > Even notepad, gawdelpus, would be better.
> >
> > When I look at your script the first sign of trouble I see is:
> >
> > Error: unexpected input in:
> > "     s[1,3,k]<- (0.1) * runif(1)+ 0.1;
> >      s[1,1,k]<- (0.02) *  runif(1)+ 0.98 ¨"
> >
> > which is the spurious character Microsoft word has helpfully inserted
> > to make it all look nice.  It's downhill all the way from there.
> >
> > (R does not expect Microsoft Word, just as "nobody expects the
> Spanish
> > Inquisition".  See http://www.youtube.com/watch?v=CSe38dzJYkY).
> >
> > Bill Venables.
> >
> > -----Original Message-----
> > From: [hidden email]
> > [mailto:[hidden email]] On Behalf Of james198877
> > Sent: Tuesday, 21 June 2011 7:13 AM
> > To: [hidden email]
> > Subject: [R] Unreasonable syntax error
> >
> > http://r.789695.n4.nabble.com/file/n3612530/PSC.r PSC.r
> >
> > Hi all,
> >
> > I just wrote a program in R by editing it in Microsoft Word and then
> > pasting
> > into the text editor of R. The above is the file.
> >
> > And below is what the console complains.... Why doesn't it recognise
> > 'r'??
> >
> > I have to mention that at least when I typed this first several lines
> > into
> > the console, the first error didn't appear. I don't try the next
> errors
> > as
> > there would be too many lines to type...I'm not sure if this is
> > something
> > about Word
> >
> > http://r.789695.n4.nabble.com/file/n3612530/lastsave.txt lastsave.txt
> >
> > Thanks a lot for your help!!!
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <[hidden email]>
> Fax-to-email: +44 (0)870 094 0861
> Date: 21-Jun-11                                       Time: 08:25:11
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Loading...