I need to execute a Perl program as part of a larger R program.
The R code generates a series of output files with different extensions, for instance .out
or .lis
.
I have a Perl program that converts those files to CSV.
I've seen Perl arguments executed on R, but nothing with this complexity.
@outfiles = glob( "*.lis" );
foreach $outfile ( @outfiles ) {
print $outfile, "
";
$outfile =~ /(S+)lis$/;
$csvfile = $1 . "lis.csv";
print $csvfile, "
";
open( OUTFILE, "$outfile" ) || die "ERROR: Unable to open $outfile
";
open( CSVFILE, ">$csvfile" ) || die "ERROR: Unable to open $csvfile
";
$lineCnt = 0;
while ( $outline = <OUTFILE> ) {
chomp( $outline );
$lineCnt++;
$outline =~ s/^s+//; # Remove whitespace at the beginning of the line
if ( $lineCnt == 1 ) {
$outline =~ s/,/./g; # Replace all the commas with periods in the hdr line
}
$outline =~ s/s+/,/g; # Replace remaining whitespace delimiters with a comma
print CSVFILE "$outline
";
}
close( OUTFILE );
close( CSVFILE );
}
Is there any way I can integrate the Perl code into my R code? I could develop an R program that does the same. But I wouldn't know where to start to convert a .lis
or .out
file to .csv
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…