I am using a Perl module from CPAN, 'Statistics::R' to pipe some 2x2 contingency table data to R and return Fisher's Exact Test results, which I then store in an array to condense and output to a biologist user.

In my test file for this, there are about 80 sets of contingency table data. These are run through using a foreach loop.

The script does what it is supposed to - about one sixth of the times it is run. The other five sixths of the time, it stops at an arbitrary point in the loop (always between two sets of contingency tables, never in the middle of one).

Below is the loop (some variable names changed). Outside of the loop are just the Statistics::R loading code and stopR command, the declarations of the variables you see in the loop (strict is on), the commands to open the files, and the command to print the contents of the array to a debugging file.

foreach my $testdata (@R_input) { $testdata =~ /(Fisher's Exact Test for Cluster \d+ \([^\)]*\))/; $R_line0 = $1; $testdata =~ /(Test\d+ <-)/; $R_line1 = ($1.$add_whitespace); $testdata =~ /(matrix\(c\(\d+, \d+, \d+, \d+\),)/; $R_line2 = ($1.$add_whitespace); $testdata =~ /(nr = 2,)/; $R_line3 = ($1.$add_whitespace); $testdata =~ /(dimnames = list\(Row1 = c\("Col1", "Col2"\),)/; $R_line4 = ($1.$add_whitespace); $testdata =~ /(Row2 = c\("Col1", "Col2"\)\)\))/; $R_line5 = $1; $testdata =~ /(fisher.test\(Test\d+\))/; $R_line6 = $1; $R_send_0 = "$R_comment_out$R_line0"; $R_send_1 = "$R_line1$R_line2$R_line3$R_line4$R_line5"; $R_send_2 = "$R_dblquotation_start$R_line6$R_send_3"; my $r_send_comment = $R_send_0; my $r_send_string = $R_send_1; my $r_send_string2 = $R_send_2; $R->send (qq'$r_send_string'); $R->send (qq'$r_send_string2'); my $ret = $R->read; push (@R_output_store, $r_send_comment); push (@R_output_store, $ret); print $ret; print "\n\n"; }

In reply to Peculiar Perl/R Problem - Memory? by maybeD

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.