R-helpers,
When I source("tmp.r") a file from within R, the code executes without
error. When I launch with 'R --no-save --no-restore < tmp.r', the code
sometimes appears to cause some type of buffer overflow and nothing gets
executed.
tmp.r contains:
myData<-c(1,0, ... long vector of numbers) followed by a new
line character and then some code to operate on myData.
It appears that when the vector is long, say 121 x 17 digits numbers, the
new line character is not recognized, because R prints a newline, but puts
the '+' continuation symbol on the next line, and does so for each
subsequent line, as follows ...
... 0.673485477583901, 0.492934866805126, 0.67+ 97955088067,
0.359755098747052, 0.734365384276714, 0.776102576892879, 1)
+ Dmatrix <- matrix (mydata, byrow=TRUE, nrow=11, ncol=11 )
+ result<-eigen(Dmatrix)
+ varEig<-var(result$values)
+ cat (c('variance of the eigenvalues:', varEig), fill=TRUE)
When the list is shorter, I don't get this problem.
Anyone have any ideas as to what is going on? The reason I am doing this
is to call R from a PERL program.
Thanks, Alex
~^^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
C. Alex Buerkle Ph: 812-855-9018
Jordan Hall 142 Fax: 812-855-6705
Department of Biology
Indiana University
Bloomington, IN 47405 cbuerkle at bio.indiana.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
source("filename") vs. input from command-line
7 messages · Alex Buerkle, Peter Dalgaard, Brian Ripley
On Wed, 21 Apr 1999, Alex Buerkle wrote:
R-helpers,
When I source("tmp.r") a file from within R, the code executes without
error. When I launch with 'R --no-save --no-restore < tmp.r', the code
sometimes appears to cause some type of buffer overflow and nothing gets
executed.
Version? OS? On my R-0.64.0 on Solaris I can do this with 1000 17-digit numbers, so I think there is particular problem with your setup.
tmp.r contains: myData<-c(1,0, ... long vector of numbers) followed by a new line character and then some code to operate on myData. It appears that when the vector is long, say 121 x 17 digits numbers, the new line character is not recognized, because R prints a newline, but puts the '+' continuation symbol on the next line, and does so for each subsequent line, as follows ...
The NL is only used to break up input: this is saying that what it has seen so far is syntactically incomplete. Is this a standard Unix text file (if you are on Unix)?
... 0.673485477583901, 0.492934866805126, 0.67+ 97955088067,
0.359755098747052, 0.734365384276714, 0.776102576892879, 1)
+ Dmatrix <- matrix (mydata, byrow=TRUE, nrow=11, ncol=11 )
+ result<-eigen(Dmatrix)
+ varEig<-var(result$values)
+ cat (c('variance of the eigenvalues:', varEig), fill=TRUE)
When the list is shorter, I don't get this problem. Anyone have any ideas as to what is going on? The reason I am doing this is to call R from a PERL program.
The obvious fix is to put the data in a separate file and use scan(), which will be more efficient (as the input does not need to go through the parser and you do not need to create R's dump format).
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 21 Apr 1999, Alex Buerkle wrote:
When I source("tmp.r") a file from within R, the code executes without
error. When I launch with 'R --no-save --no-restore < tmp.r', the code
sometimes appears to cause some type of buffer overflow and nothing gets
executed.
BR> Version? OS? On my R-0.64.0 on Solaris I can do this ... I am using R-0.63.3 on linux-x86.
It appears that when the vector is long, say 121 x 17 digits numbers, the new line character is not recognized, because R prints a newline, but puts the '+' continuation symbol on the next line, and does so for each subsequent line, as follows ...
BR> The NL is only used to break up input: this is saying that what it BR> has seen so far is syntactically incomplete. Is this a standard BR> Unix text file (if you are on Unix)? It is a standard text file. If it were syntactially incomplete, sourcing it from the R prompt would fail, but it doesn't.
... 0.673485477583901, 0.492934866805126, 0.67+ 97955088067,
0.359755098747052, 0.734365384276714, 0.776102576892879, 1)
+ Dmatrix <- matrix (mydata, byrow=TRUE, nrow=11, ncol=11 )
+ result<-eigen(Dmatrix)
+ varEig<-var(result$values)
+ cat (c('variance of the eigenvalues:', varEig), fill=TRUE)
When the list is shorter, I don't get this problem.
What I have ended up doing is calling R from PERL or the command line
with the following:
echo "source ('tmp0.r')" | R --no-save --no-restore
This works.
I am still not clear on why the command-line redirection did not work
(R --no-save --no-restore < tmp.r). Is there a difference between how
R handles input received from a unix pipe versus from redirection?
- Alex
~^^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
C. Alex Buerkle Ph: 812-855-9018
Jordan Hall 142 Fax: 812-855-6705
Department of Biology
Indiana University
Bloomington, IN 47405 cbuerkle at bio.indiana.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Alex Buerkle <cbuerkle at bio.indiana.edu> writes:
echo "source ('tmp0.r')" | R --no-save --no-restore
This works.
I am still not clear on why the command-line redirection did not work
(R --no-save --no-restore < tmp.r). Is there a difference between how
R handles input received from a unix pipe versus from redirection?
No. But there are substantial differences between how it handles
source() vs. how it deals with redirected input. Try deciphering the
source function and you'll see.
As to your original problem: From 0.63.3 to 0.64.0
BUG FIXES
o strsplit(), scan() and friends use a much larger char buffer
(still fixed size; this will change again)
and 0.64.1 (out in a fortnight or so) will have
o load / save / data allow unlimited string sizes.
o strsplit() allows unlimited string size.
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 22 Apr 1999, Alex Buerkle wrote:
On Wed, 21 Apr 1999, Alex Buerkle wrote:
When I source("tmp.r") a file from within R, the code executes without
error. When I launch with 'R --no-save --no-restore < tmp.r', the code
sometimes appears to cause some type of buffer overflow and nothing gets
executed.
BR> Version? OS? On my R-0.64.0 on Solaris I can do this ... I am using R-0.63.3 on linux-x86.
It appears that when the vector is long, say 121 x 17 digits numbers, the new line character is not recognized, because R prints a newline, but puts the '+' continuation symbol on the next line, and does so for each subsequent line, as follows ...
BR> The NL is only used to break up input: this is saying that what it BR> has seen so far is syntactically incomplete. Is this a standard BR> Unix text file (if you are on Unix)? It is a standard text file. If it were syntactially incomplete, sourcing
That is not what I asked!
it from the R prompt would fail, but it doesn't.
But the version read from the file is syntactically incomplete.... This implies that something is going wrong in the read.
I am still not clear on why the command-line redirection did not work (R --no-save --no-restore < tmp.r). Is there a difference between how R handles input received from a unix pipe versus from redirection?
Not on my system, and as it does work for me on Solaris, the problem seems to be specific to something in your version.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian D Ripley <ripley at stats.ox.ac.uk> writes:
On Thu, 22 Apr 1999, Alex Buerkle wrote:
It appears that when the vector is long, say 121 x 17 digits numbers, the new line character is not recognized, because R prints a newline, but puts the '+' continuation symbol on the next line, and does so for each subsequent line, as follows ...
BR> The NL is only used to break up input: this is saying that what it BR> has seen so far is syntactically incomplete. Is this a standard BR> Unix text file (if you are on Unix)? It is a standard text file. If it were syntactially incomplete, sourcing
That is not what I asked!
it from the R prompt would fail, but it doesn't.
But the version read from the file is syntactically incomplete.... This implies that something is going wrong in the read.
Hehe. You've been doing too little Perl hacking, Brian! When a Perl hacker says that he has 121 17 digit numbers followed by a NL, he means that he has *one* input line which is over 2k long... I can reproduce the behaviour with an old pre-0.63.3, the new versions have improved:
x<-c(0.2540311, -0.6709876, -0.3677535, 0.5153803, 0.08444575, -0.6793758..
...-1.476418, -0.5809392, 0.48Error: syntax error Execution halted Well, kind of improved... I'm not sure this is very easy to fix. R_ReadConsole deals in 1024 byte buffers in several places. The workaround should be obvious, though.
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 22 Apr 1999, Peter Dalgaard BSA wrote:
Prof Brian D Ripley <ripley at stats.ox.ac.uk> writes:
On Thu, 22 Apr 1999, Alex Buerkle wrote:
It appears that when the vector is long, say 121 x 17 digits numbers, the new line character is not recognized, because R prints a newline, but puts the '+' continuation symbol on the next line, and does so for each subsequent line, as follows ...
BR> The NL is only used to break up input: this is saying that what it BR> has seen so far is syntactically incomplete. Is this a standard BR> Unix text file (if you are on Unix)? It is a standard text file. If it were syntactially incomplete, sourcing
That is not what I asked!
it from the R prompt would fail, but it doesn't.
But the version read from the file is syntactically incomplete.... This implies that something is going wrong in the read.
Hehe. You've been doing too little Perl hacking, Brian! When a Perl hacker says that he has 121 17 digit numbers followed by a NL, he means that he has *one* input line which is over 2k long...
To, the contrary, I have been doing far too much recently, as you will see when Rd2hlp gets released. To the point that I would never do that, and precisely my point about the file: there had to be something unusual about it.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._