Skip to content

source("filename") vs. input from command-line

7 messages · Alex Buerkle, Peter Dalgaard, Brian Ripley

#
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, 21 Apr 1999, Alex Buerkle wrote:

            
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.
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)?
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).
#
On Wed, 21 Apr 1999, Alex Buerkle wrote:
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.
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.
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:
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.
#
On Thu, 22 Apr 1999, Alex Buerkle wrote:

            
That is not what I asked!
But the version read from the file is syntactically incomplete.... This
implies that something is going wrong in the read.
Not on my system, and as it does work for me on Solaris, the problem seems
to be specific to something in your version.
#
Prof Brian D Ripley <ripley at stats.ox.ac.uk> writes:
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:
...-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.
#
On 22 Apr 1999, Peter Dalgaard BSA wrote:

            
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.