#!/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; } save_array_output(@lines, ".out"); print "\@lines = \n @lines "; my $R = Statistics::R->new() ; $R->startR ; $R -> send('library(genetics);'); $R -> send('table <- read.table("/home/user/my_path/data_freq.txt.out", header=T, row.names=2);'); $R -> send('g1 <- table[, 2];'); $R -> send('meang1 <- mean(g1)'); $R -> send('print(meang1);'); $R -> send('write.table(g1, "/home/user/my_path/g1.txt");'); $R -> send('write.table(meang1, "/home/user/my_path/meang1.txt");'); #my @results1 = get('g1'); print "\@results1 = ", @results1, "\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 }