OK. Statistics::R seens to be working fine now

I just ignores the error message in the test and went ahead with the installation, just as was told me in here: http://www.perlmonks.org/?node_id=1009156

But still I have two problems (that I hope are the last ones).

First of all, when I try to pass my table from perl to R with the comand "$R -> set( 'table', \@lines );", it returns this error:

Problem running this R command: g1 <- table[, 3]; Got the error: wrong number of dimmensions

I scaped that creating an output file from perl (named "data_freq.txt.out" and telling R to import from that. But this doesnt seens the right way to do it.

Second. When I try to return a table from R to perl, importing it to an array (in "my @results1 = $R->get('g1');"), I would like all the values in the table to be passed to this array (@results1). So I could shift and pop values from that array to use in other perl things (Mostly to create an nice output file)

Instead, what I get is an array with a single element that is some kind of octodecimal value (I guess)

How can I fix that?

Someone already told me to use "$results1" instead of "@results1". But that gives me the same output. Besides, it will create an scalar and that is not what I want

NOTE: "my $media = $R->get('meang1');" do work! I guess thats is because its a single value.

HERE are my codes, wich I call with "./perl-R4.pl data_freq.txt"

perl-R4.pl

#!/usr/bin/perl use strict; use warnings; use Statistics::R; my @lines; my $line; my $csv_check = shift @ARGV; #Mark for csv check----- @ARGV = $csv_check; while ( defined( $line = <> ) ) { push @lines, $line; } shift @lines; save_array_output(@lines, ".out"); print "\@lines = \n @lines "; my $R = Statistics::R->new() ; $R->startR ; $R->run('library(genetics);'); $R->run('setwd("/home/user/tests/");'); #$R->set( 'table', \@lines ); $R->run('table <- read.table("/home/user/tests/data_freq.txt.out");'); $R->run('g1 <- table[, 3];'); $R->run('meang1 <- mean(g1)'); $R->run('print(meang1);'); $R->run('write.table(g1, "g1.txt");'); $R->run('write.table(meang1, "meang1.txt");'); my $media = $R->get('meang1'); my $results1 = $R->get('g1'); print "\$results1 = ", $results1, "\n"; print "\$media = ", $media, "\n"; $R->stopR() ; #----------------------------------------------- sub save_array_output { @lines = @_; my $mid_name = pop @lines; my $output_name = $csv_check.$mid_name; open(MYOUTFILE, ">:utf8", $output_name); # Open output file print MYOUTFILE "@lines \n"; close(MYOUTFILE); # Close output file }

data_freq.txt

Locus Alleles frequencies Bet01 230 0.166666666666666657415 Bet01 238 0.500000000000000000000 Bet01 244 0.333333333333333314830 Bet05 101 0.285714285714285698425 Bet05 103 0.500000000000000000000 Bet05 105 0.142857142857142849213 Bet05 109 0.071428571428571424606 Bet06 138 0.055555555555555552472 Bet06 140 0.111111111111111104943 Bet06 146 0.833333333333333370341 Bet12 108 0.111111111111111104943 Bet12 110 0.055555555555555552472 Bet12 112 0.444444444444444419773 Bet12 114 0.277777777777777790114 Bet12 116 0.055555555555555552472 Bet12 118 0.055555555555555552472

In reply to Re: Calling R in perl by blackzero
in thread Calling R in perl by blackzero

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.