bricas / statistics-r Goto Github PK
View Code? Open in Web Editor NEWControls the R (R-project) interpreter through Perl
Home Page: http://metacpan.org/release/Statistics-R/
Controls the R (R-project) interpreter through Perl
Home Page: http://metacpan.org/release/Statistics-R/
When I run Statistics::R in perl, I came across the error:
Can't call method "run" on an undefined value at /usr/local/lib/perl5/site_perl/5.22.0/Statistics/R.pm line 451, line XXX.
The code are:
my $R = Statistics::R->new();
$R->set('case',[@ca]);
$R->set('ctrl',[@ctrl]);
$R->run(q'p_value <- wilcox.test(case,ctrl)$p.value');
my $return= $R->get('p_value');
$R->run(q'case_mean = mean(case,na.rm=T)');
my $return1= $R->get('case_mean');
print $return,"\n";
print $return1,"\n";
I run the script and get some results, but it was terminated by the error.
The imported data have been checked and seems nothing wrong.
Any suggestions? thanks
Statistics::R latest version
Perl --version (v5.22.0) built for x86_64-linux-thread-multi
R version 3.4.1 (2017-06-30) -- "Single Candle"
Platform: x86_64-pc-linux-gnu (64-bit)
Hi, when I pass a long array using $R->set
, it will cause error. So I need to pass the long array part by part
sub passVectorToR
{
my $varname = shift;
my $vector = shift;
my $slice = 200;
$R->send("$varname <- c()");
for (my $offset = 0; $offset < scalar @{$vector}; $offset += $slice) {
my $end = $offset + $slice;
if ($end > scalar @{$vector}) {
$end = scalar @{$vector};
}
my @tmp = @{$vector}[$offset..($end - 1)];
$R->set('tmp123', \@tmp);
$R->send("$varname <- c($varname, tmp123)");
}
}
I think this work would be better done in sub set
.
I use Statistics::R want to improve the speed of for(),but I found it even worse.
So how to do that?
Hello Florent,
is there any way to set an element of an array to NA?
regards
ale
Hello Florent,
I was trying to install Statistics::R (0.34) through CPAN using Perl 5.22, to be able to use Grinder, but the installation failed. A few messages that appear repeatedly are "Invalid argument opening STDIN as Win32 handle 352 in pumper 6068" and "Warning: unable to close filehandle GEN5 properly: Bad file descriptor during global destruction.".
Below is the complete output:
Microsoft Windows [Versión 10.0.10586]
(c) 2015 Microsoft Corporation. Todos los derechos reservados.
C:\Users\Francisco>cpan
Loading internal null logger. Install Log::Log4perl for logging messages
cpan shell -- CPAN exploration and modules installation (v2.11)
Enter 'h' for help.
cpan> install Statistics::R
Database was generated on Wed, 02 Dec 2015 21:40:46 GMT
Running install for module 'Statistics::R'
Checksum for C:\STRAWB~1\cpan\sources\authors\id\F\FA\FANGLY\Statistics-R-0.34.tar.gz ok
Scanning cache C:\STRAWB~1\cpan\build for sizes
............................................................................DONE
Configuring F/FA/FANGLY/Statistics-R-0.34.tar.gz with Makefile.PL
Value of <HANDLE> construct can be "0"; test with defined() at C:\Strawberry\perl\site\lib/CPAN/Reporter.pm line 1160.
Locating bin:R... found at C:\Program Files\R\R-3.2.2\bin\R.EXE.
Checking if your kit is complete...
Looks good
Generating a dmake-style Makefile
Writing Makefile for Statistics::R
Writing MYMETA.yml and MYMETA.json
(C:\Strawberry\perl\bin\perl.exe Makefile.PL exited with 0)
CPAN::Reporter: Makefile.PL result is 'pass', No errors.
FANGLY/Statistics-R-0.34.tar.gz
C:\Strawberry\perl\bin\perl.exe Makefile.PL -- OK
Running make for F/FA/FANGLY/Statistics-R-0.34.tar.gz
cp lib/Statistics/R.pm blib\lib\Statistics\R.pm
cp lib/Statistics/R/Legacy.pm blib\lib\Statistics\R\Legacy.pm
cp lib/Statistics/R/Win32.pm blib\lib\Statistics\R\Win32.pm
(C:\STRAWB~1\c\bin\dmake.exe exited with 0)
CPAN::Reporter: dmake result is 'pass', No errors.
FANGLY/Statistics-R-0.34.tar.gz
C:\STRAWB~1\c\bin\dmake.exe -- OK
Running make test
"C:\Strawberry\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'inc', 'blib\lib', 'blib\arch')" t/*.t
# Testing Statistics::R 0.34, Perl 5.022000, C:\Strawberry\perl\bin\perl.exe
t/00-load.t ........ ok
t/01-pod.t ......... ok
Invalid argument opening STDIN as Win32 handle 352 in pumper 6068 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
Invalid argument opening STDIN as Win32 handle 396 in pumper 12664 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
ack Invalid argument: read( 9 ) at C:/Strawberry/perl/vendor/lib/IPC/Run/IO.pm line 558.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 22 just after 1.
Warning: unable to close filehandle GEN5 properly: Bad file descriptor during global destruction.
Warning: unable to close filehandle GEN10 properly: Bad file descriptor during global destruction.
Invalid argument opening STDIN as Win32 handle 400 in pumper 14712 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
t/02-legacy.t ......
Dubious, test returned 22 (wstat 5632, 0x1600)
All 1 subtests passed
Invalid argument opening STDIN as Win32 handle 360 in pumper 9152 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
Invalid argument opening STDIN as Win32 handle 416 in pumper 7048 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
Invalid argument opening STDIN as Win32 handle 388 in pumper 8024 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
ack Invalid argument: read( 11 ) at C:/Strawberry/perl/vendor/lib/IPC/Run/IO.pm line 558.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 22 just after 3.
Warning: unable to close filehandle GEN5 properly: Bad file descriptor during global destruction.
Warning: unable to close filehandle GEN10 properly: Bad file descriptor during global destruction.
t/03-run.t .........
Dubious, test returned 22 (wstat 5632, 0x1600)
All 3 subtests passed
Invalid argument opening STDIN as Win32 handle 396 in pumper 16396 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
Invalid argument opening STDIN as Win32 handle 284 in pumper 16008 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
Invalid argument opening STDIN as Win32 handle 416 in pumper 13144 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
ack Invalid argument: read( 9 ) at C:/Strawberry/perl/vendor/lib/IPC/Run/IO.pm line 558.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 22 just after 5.
Warning: unable to close filehandle GEN10 properly: Bad file descriptor during global destruction.
Warning: unable to close filehandle GEN5 properly: Bad file descriptor during global destruction.
t/04-start-stop.t ..
Dubious, test returned 22 (wstat 5632, 0x1600)
All 5 subtests passed
Invalid argument opening STDIN as Win32 handle 384 in pumper 6688 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
Invalid argument opening STDIN as Win32 handle 404 in pumper 7400 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
ack Invalid argument: read( 9 ) at C:/Strawberry/perl/vendor/lib/IPC/Run/IO.pm line 558.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 22 just after 8.
Warning: unable to close filehandle GEN5 properly: Bad file descriptor during global destruction.
Warning: unable to close filehandle GEN10 properly: Bad file descriptor during global destruction.
Invalid argument opening STDIN as Win32 handle 412 in pumper 14216 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
t/05-shared.t ......
Dubious, test returned 22 (wstat 5632, 0x1600)
All 8 subtests passed
Invalid argument opening STDIN as Win32 handle 352 in pumper 464 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
Invalid argument opening STDIN as Win32 handle 408 in pumper 11780 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
ack Invalid argument: read( 9 ) at C:/Strawberry/perl/vendor/lib/IPC/Run/IO.pm line 558.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 22 just after 1.
Warning: unable to close filehandle GEN5 properly: Bad file descriptor during global destruction.
Warning: unable to close filehandle GEN10 properly: Bad file descriptor during global destruction.
Invalid argument opening STDIN as Win32 handle 416 in pumper 3384 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
t/06-get-set.t .....
Dubious, test returned 22 (wstat 5632, 0x1600)
All 1 subtests passed
Invalid argument opening STDIN as Win32 handle 136 in pumper 7264 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
Invalid argument opening STDIN as Win32 handle 392 in pumper 6724 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
ack Invalid argument: read( 9 ) at C:/Strawberry/perl/vendor/lib/IPC/Run/IO.pm line 558.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 22 just after 1.
Warning: unable to close filehandle GEN10 properly: Bad file descriptor during global destruction.
Warning: unable to close filehandle GEN5 properly: Bad file descriptor during global destruction.
Invalid argument opening STDIN as Win32 handle 396 in pumper 6888 at C:/Strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
t/07-robust.t ......
Dubious, test returned 22 (wstat 5632, 0x1600)
All 1 subtests passed
t/08-errors.t ...... ok
Test Summary Report
-------------------
t/02-legacy.t (Wstat: 5632 Tests: 1 Failed: 0)
Non-zero exit status: 22
Parse errors: No plan found in TAP output
t/03-run.t (Wstat: 5632 Tests: 3 Failed: 0)
Non-zero exit status: 22
Parse errors: No plan found in TAP output
t/04-start-stop.t (Wstat: 5632 Tests: 5 Failed: 0)
Non-zero exit status: 22
Parse errors: No plan found in TAP output
t/05-shared.t (Wstat: 5632 Tests: 8 Failed: 0)
Non-zero exit status: 22
Parse errors: No plan found in TAP output
t/06-get-set.t (Wstat: 5632 Tests: 1 Failed: 0)
Non-zero exit status: 22
Parse errors: No plan found in TAP output
t/07-robust.t (Wstat: 5632 Tests: 1 Failed: 0)
Non-zero exit status: 22
Parse errors: No plan found in TAP output
Files=9, Tests=24, 4 wallclock secs ( 0.05 usr + 0.06 sys = 0.11 CPU)
Result: FAIL
Failed 6/9 test programs. 0/24 subtests failed.
dmake.exe: Error code 255, while making 'test_dynamic'
(C:\STRAWB~1\c\bin\dmake.exe test exited with 65280)
CPAN::Reporter: Test result is 'fail', One or more tests failed.
CPAN::Reporter: preparing a CPAN Testers report for Statistics-R-0.34
CPAN::Reporter: this appears to be a duplicate report for the test phase:
FAIL Statistics-R-0.34 MSWin32-x64-multi-thread 6.3
Test report will not be sent.
FANGLY/Statistics-R-0.34.tar.gz
C:\STRAWB~1\c\bin\dmake.exe test -- NOT OK
//hint// to see the cpan-testers results for installing this module, try:
reports FANGLY/Statistics-R-0.34.tar.gz
Stopping: 'install' failed for 'Statistics::R'.
Failed during this command:
FANGLY/Statistics-R-0.34.tar.gz : make_test NO
cpan>
Thanks
Francisco
I'm calling multiple r files using the run_from_file command.
my @r = qw( r_file1 r_file2 ); my $R = Statistics::R->new(); foreach my $file (@r) { my $t = $R->run_from_file( $file ); }
I spent some time to reproduce a strange behavior. Finally found out, that a quit()
command inside one of the r-files causes the $R object in perl to quit as well. Unfortunately there's no error, so alle further files pass (without notification). Maybe you could mention this in the doc! It would be great to identify if a script is called by the module?!
note: I replaced quit()
in the r files by rm(list = ls())
to save memory.
ps: many thx for this module, it really helped me out a lot!
The below commands should be equivalent, but the latter causes an error. Seems like this is because wrap_cmd
adds on a semicolon without checking to see if an actual command proceeds it:
statistics-r/lib/Statistics/R.pm
Line 810 in f5dbc80
use Statistics::R;
my $R = Statistics::R->new();
$R->run(qq{
a = 1;
b = 2;}); # no error
$R->run(qq{
a = 1;
b = 2;\n\n}); # error because of newline
The output is
Problem while running this R command:
a = 1;
b = 2;
Error:
unexpected ';' in " ;"
Execution halted
Hi,
I am using Statistics::R
in my code and added a timeout for certain operations in R by overriding the ALRM
signal. When I catch ALRM
I would like to stop the R child process. However, stop
waits until my R operation finished. I then kill the process manually. This works in general, but when my Statistics::R
object goes out of scope and DESTROY
is called, I get the error message
(in cleanup) Error stopping R: 9
about the kill signal that I sent.
Example:
use strict;
use warnings;
use Statistics::R;
my $R = Statistics::R->new;
# timeout: 2 seconds
my $timeout = 2;
eval {
local $SIG{ALRM} = sub { die("Timed Out"); };
alarm($timeout);
# long-running command
$R->run("x <- mean(rt(100000000, df = 4))");
alarm(0);
};
if ($@) {
print $@;
# kill process since $R->stop would wait until the R command finishes
kill 9, $R->pid;
}
The error does no do any harm since my $R
object is of scope anyways, but is there maybe a cleaner way to do this? Would it make sense to maybe check in DESTROY
whether the pid of the child still exists (although this might be tricky for all platforms)? Or maybe even add such a timeout mechanism to the run
subroutine?
Many thanks in advance, Best Regards,
Hannes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.