Subject: | read() fails to capture some output |
Hi Adam,
R seems to love printing column names and such along with variable
value, which makes it a little bit klunky to capture the value of a
variable using Statistics::R->read().
I was researching it there are any options in R to make it a little bit
less verbose and found a command that seems to only display the variable
value in the terminal:
write.table(mean, file="", row.names=FALSE, col.names=FALSE)
However, it appears that Statistics::R->read fails to capture the
content output by this command.
I attached two files to reproduce the bug. If I run:
cat fit.R | R --slave --vanilla
The output is:
Kolmogorov-Smirnov statistic: 0.1104554
Kolmogorov-Smirnov test: not calculated
Cramer-von Mises statistic: 0.02848332
Cramer-von Mises test: not rejected
Anderson-Darling statistic: 0.225598
Anderson-Darling test: not rejected
mean
10.41111
10.4111111111111
Now if I run the same R commands through the Statistics::R interface:
perl ./statistics_r_test.pl
I get:
Kolmogorov-Smirnov statistic: 0.1104554
Kolmogorov-Smirnov test: not calculated
Cramer-von Mises statistic: 0.02848332
Cramer-von Mises test: not rejected
Anderson-Darling statistic: 0.225598
Anderson-Darling test: not rejected mean
10.41111
The output line corresponding to the R command write.table() is missing
from the Statistics::R output.
Thanks for your help,
Florent
Subject: | statistics_r_test.pl |
#! /usr/bin/env perl
use strict;
use warnings;
use Statistics::R;
my $out = '';
my $R = Statistics::R->new();
$R->startR;
$R->send(q`library(fitdistrplus)`);
$out .= $R->read;
$R->send(qq`x1 <- c(6.4, 13.3, 4.1, 1.3, 14.1, 10.6, 9.9, 9.6, 15.3, 22.1, 13.4, 13.2, 8.4, 6.3, 8.9, 5.2, 10.9, 14.4)`);
$out .= $R->read;
$R->send(q`f1l <- fitdist(x1, "norm")`);
$out .= $R->read;
$R->send(q`gofstat(f1l, print.test = TRUE)`);
$out .= $R->read;
$R->send(q`mean <- f1l$estimate[1]`);
$out .= $R->read;
$R->send(q`print(mean)`);
$out .= $R->read;
$R->send(q`write.table(mean, file="", row.names=FALSE, col.names=FALSE)`);
$out .= $R->read;
$R->stopR();
print $out;
exit;
Subject: | fit.R |
Message body not shown because it is not plain text.