use R; # This tests the AUTOLOAD feature of the R package in Perl. # It will call the sum function directly from R::sum(). &R::initR("--silent"); $x = &R::sum(1,2,3); print "Sum = $x\n"; #### # Calculate HWE goodness-of-fit p-value # Simply for readability of code passed to R @x = @{ $alleles1 }; @y = @{ $alleles2 }; @fail = qw( FL PF NTC ); # Create a locus for the data, passing to a string in Perl $loc = &R::callWithNames( "locus", { 'allele1', \@x, 'allele2', \@y, 'locus.alias', $site, 'miss.val', \@fail } ); # Calculate HWE for valid sites, otherwise print error $testForNA = &R::call( "is.na", $loc ); if ( &R::call( "all", $testForNA ) == 1 ) { $hwe = "-"; } else { $hwe = &R::call( "hwe", $loc ); $hwe = sprintf( "%.4f", $hwe->getEl("gof.pval") ); #&R::call("print", $hwe); } return ( $hwe ); #### sub DESTROY { my $obj = $_[0]; print "Destroying R reference object `", $obj->{name}, "'\n"; R::deleteRReference($_[0]); 1; }