Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array length limit? #6

Open
zwzmzd opened this issue Apr 14, 2015 · 3 comments
Open

Array length limit? #6

zwzmzd opened this issue Apr 14, 2015 · 3 comments

Comments

@zwzmzd
Copy link

zwzmzd commented Apr 14, 2015

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.

@fangly
Copy link
Collaborator

fangly commented Apr 14, 2015

Hi zmzmzd,
Please try the latest version of Statistics::R:
0.33 2014-08-28
- Better way to set large arrays (patch by Ken Yamaguchi, RT #97359)
If that does not fix your problem, you will need to give us more details, e.g. your R version.
Cheers,
Florent

@zwzmzd
Copy link
Author

zwzmzd commented Apr 14, 2015

Hi,

Yes I am using Statistics::R 0.33, my R version is 3.1.2

This is my test code, I use set then get. If I use passVectorToR('Tnum', \@arrin) instead of $R->set('Tnum', \@arrin), It can work properly.

The data file output.txt can be downloaded from https://www.dropbox.com/s/iu4mub6z97dpnu2/output.txt?dl=0

open my $in,  '<',  "output.txt"  or die "Can't read $infile: $!\n"; 
my @arrin = ();
while (my $line=<$in>) { 
    $line =~ s/[\r\n]//;
    push @arrin, $line;
} 
close $in;

$R->set('Tnum', \@arrin); # can be replaced by passVectorToR
my $res = $R->get('Tnum');
print "length ", scalar @{$res}, "\n";

@fangly
Copy link
Collaborator

fangly commented Sep 28, 2015

Hi zwzmzd,

Thanks for the complementary details. Note that your snippet of code does not work as-is and that you did not provide the error message you got. On my end, unfortunately, I do not manage to reproduce the bug.

For information, I run this software:
Linux x86_64
R 3.2.2
Perl 5.20.2
IPC::Run 0.94
Regexp::Common 2013031301
Text::Balanced 2.02
Text::Wrap 2013.0523
version 0.9909

My advice is to upgrade these perl modules one-by-one until you (hopefully) get things working. Please tell me if you are successful this way.

Also, the ./t/08-robust.t file tests that get() and set() methods work with arrays of 100,000 elements.
If you installed Statistics::R properly, i.e. you also ran the test suite during installation, then I do not understand how this test could pass considering the bug you report...

Cheers,

Florent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants