An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070301/9a707814/attachment.pl
Generating R plots through Perl
5 messages · Ryan.G.Huckstorf at wellsfargo.com, Charilaos Skiadas, Horace Tso
On Mar 1, 2007, at 6:28 PM, <Ryan.G.Huckstorf at wellsfargo.com> wrote:
First off, if you are working in perl you might want to be aware of ruby and the "r for ruby" project: http://rubyforge.org/projects/r4ruby/
Hello,
$R->send(qq (xVal <- c(1,2,3,4,5,6)));
$R->send(qq (yVal <- c(3,5,2,6,1,5)));
$R->send(qq (pdf("C:/Test Environment/R/perlPlotTest.pdf")));
$R->send(qq (plot(xVal, yVal)));
$R->send(qq (graphics.off()));
I don't really know how to write this in perl, but could you perhaps
put the last three lines all in one call to "$R->send", using dev.off
() then? Don't know if it would make a difference, but that's the
only thing I could think of. I'm guessing something like this:
$R->send(qq (pdf("C:/Test Environment/R/perlPlotTest.pdf"); plot
(xVal, yVal); dev.off()));
As the code indicates, I am using R's pdf function to create a pdf file containing the plot of xVal and yVal. I am using the graphics.off() function rather than the dev.off() function as I get an error message of "<simpleError in dev.off(): cannot shut down device 1 (the null device)>" when dev.off() is used. Is there another way to generate and save a plot using the bridge connection that I described? If not, what would be an efficient way of generating and saving plots from within my Perl program? Any help would be greatly appreciated. Thank you, Ryan
Haris Skiadas Department of Mathematics and Computer Science Hanover College
4 days later
Hello,
I tried what you suggested (i.e. combine the separate plot creation
commands into one command from Perl to R), and it worked. The syntax is
as follows:
$R->send(qq (xVal <- c(1,2,3,4,5,6)));
$R->send(qq (yVal <- c(3,5,2,6,1,5)));
$R->send(qq (c(pdf("C:/Test Environment/R/perlPlotTest.pdf"), plot(xVal,
yVal), dev.off())));
I appreciate your help with this, and I will look into ruby and the "r
for ruby" project for future use.
Thanks again,
Ryan
-----Original Message-----
From: Charilaos Skiadas [mailto:skiadas at hanover.edu]
Sent: Thursday, March 01, 2007 6:15 PM
To: Huckstorf, Ryan
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Generating R plots through Perl
On Mar 1, 2007, at 6:28 PM, <Ryan.G.Huckstorf at wellsfargo.com> wrote:
First off, if you are working in perl you might want to be aware of ruby and the "r for ruby" project: http://rubyforge.org/projects/r4ruby/
Hello,
$R->send(qq (xVal <- c(1,2,3,4,5,6))); $R->send(qq (yVal <-
c(3,5,2,6,1,5))); $R->send(qq (pdf("C:/Test
Environment/R/perlPlotTest.pdf")));
$R->send(qq (plot(xVal, yVal)));
$R->send(qq (graphics.off()));
I don't really know how to write this in perl, but could you perhaps put
the last three lines all in one call to "$R->send", using dev.off
() then? Don't know if it would make a difference, but that's the only
thing I could think of. I'm guessing something like this:
$R->send(qq (pdf("C:/Test Environment/R/perlPlotTest.pdf"); plot (xVal,
yVal); dev.off()));
As the code indicates, I am using R's pdf function to create a pdf file containing the plot of xVal and yVal. I am using the graphics.off() function rather than the dev.off() function as I get an
error message of "<simpleError in dev.off(): cannot shut down device 1
(the null device)>" when dev.off() is used. Is there another way to generate and save a plot using the bridge connection that I described?
If not, what would be an efficient way of generating and saving plots from within my Perl program? Any help would be greatly appreciated. Thank you, Ryan
Haris Skiadas Department of Mathematics and Computer Science Hanover College
Dear list,
It's never happened to me before in such a simple exercise but is not going away and I've checked my data are good. I want a simple lm model with one response and one predictor, where N is about 4,200 * data set not exactly small. Both x and y are nice, continuous variables having NA filtered out with a call to na.omit. So I did
mod = lm( y ~ x, data=x1)
Then the error,
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
NA/NaN/Inf in foreign function call (arg 4)
I did a trace back and it turned out it's an error thrown by the Fortran subroutine that seems to be trying a QR decomposition,
traceback()
3: .Fortran("dqrls", qr = x, n = n, p = p, y = y, ny = ny, tol = as.double(tol),
coefficients = mat.or.vec(p, ny), residuals = y, effects = y,
rank = integer(1), pivot = 1:p, qraux = double(p), work = double(2 *
p), PACKAGE = "base")
2: lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)
1: lm(log.p.sales ~ log.mktcap, data = x1)
My question is why would QR fail since the default in lm.fit is 'singular.ok' ? Furthermore, is there a way to get around presumably a singularity in my design matrix?
Thanks in advance.
Horace W. Tso
Folks, apologize for such an obvious oversight on my part. The reason qr fails is, one of the data points has value of -Inf (response is actually the log of something, and I have a zero in the original set). That explains the error message in call to dqrls. I should have taken the mean of the response before proceeding and that would tell me right away what's wrong. Thanks. H.
"Horace Tso" <Horace.Tso at pgn.com> 3/6/2007 1:45:28 PM >>>
Dear list,
It's never happened to me before in such a simple exercise but is not
going away and I've checked my data are good. I want a simple lm model
with one response and one predictor, where N is about 4,200 * data set
not exactly small. Both x and y are nice, continuous variables having NA
filtered out with a call to na.omit. So I did
mod = lm( y ~ x, data=x1)
Then the error,
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)
:
NA/NaN/Inf in foreign function call (arg 4)
I did a trace back and it turned out it's an error thrown by the
Fortran subroutine that seems to be trying a QR decomposition,
traceback()
3: .Fortran("dqrls", qr = x, n = n, p = p, y = y, ny = ny, tol =
as.double(tol),
coefficients = mat.or.vec(p, ny), residuals = y, effects = y,
rank = integer(1), pivot = 1:p, qraux = double(p), work =
double(2 *
p), PACKAGE = "base")
2: lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)
1: lm(log.p.sales ~ log.mktcap, data = x1)
My question is why would QR fail since the default in lm.fit is
'singular.ok' ? Furthermore, is there a way to get around presumably a
singularity in my design matrix?
Thanks in advance.
Horace W. Tso
______________________________________________
R-help at stat.math.ethz.ch 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.