R::YapRI::Block.pm
A module to segment the R commands.
use R::YapRI::Base; ## WORKING WITH COMMAND BLOCKS: my $rbase = R::YapRI::Base->new(); ## Create a file-block_1 my $rblock1 = $rbase->create_block('BLOCK1'); $rblock1->add_command('x <- c(10, 9, 8, 5)'); $rblock1->add_command('z <- c(12, 8, 8, 4)'); $rblock1->add_command('x + z') ## Get name or rbase my $blockname = $rblock1->get_blockname(); my $rbase = $rblock1->get_rbase(); ## Create a file-block_2 my $rblock2 = $rbase->create_block('BLOCK2'); $rblock2->add_command('bmp(filename="myfile.bmp", width=600, height=800)'); $rblock2->add_command('dev.list()'); $rblock2->add_command('plot(c(1, 5, 10), type = "l")'); ## Run each block $rblock1->run_block(); $rblock2->run_block(); ## Get the results my $resultfile1 = $rblock1->get_resultfile(); my $resultfile2 = $rblock2->get_resultfile(); ## Combine block before run it my $newblock = $rbase->combine_blocks(['BLOCK1', 'BLOCK2'], 'NEWBLOCK'); $newblock->run_block();
A wrapper to use blocks with R::YapRI::Base.
Use blocks through rbase object.
Aureliano Bombarely <ab782@cornell.edu>
The following class methods are implemented:
There are two ways to create a new block:
1) Through rbase object.
my $rblock = $rbase->new_block($blockname);
2) Through R::YapRI::Block class
my $rblock = R::YapRI::Block->new($rbase, $blockname);
Both methods will add the new block to the rbase object.
Usage: my $rblock = R::YapRI::Block->new($rbase, $blockname); Desc: Create a new R block object associated with a R::YapRI::Base object Ret: a R::YapRI::Block object Args: $rbase, a R::YapRI::Base object. $blockname, an scalar, a blockname $cmdfile, a filename with the command file (optional). Side_Effects: Die if no arguments are used. Die if $rbase argument is not a R::YapRI::Base object. Create a new command file if no commandfile is supplied. Add the block created to rbase object. Example: my $rblock = R::YapRI::Block->new($rbase, 'MyBlock');
No set accessors have been created for rbase or blockname. They are controlled by R::YapRI::Base object.
Usage: my $rbase = $rblock->get_rbase(); Desc: Get rbase object from rblock Ret: $rbase, a R::YapRI::Base object Args: None Side_Effects: None Example: my $rbase = $rblock->get_rbase();
Usage: my $blockname = $rblock->get_blockname(); Desc: Get blockname from rblock object Ret: $blockname, name of the block, an alias for cmdfile. Args: None Side_Effects: None Example: my $blockname = $rblock->get_blockname();
Usage: my $filename = $rblock->get_command_file(); Desc: Get filename of the block from rbase object Ret: $filename, the command filename for the block associated to rbase. Args: None Side_Effects: None Example: my $filename = $rblock->get_command_file();
Usage: $rblock->set_command_file($filename); Desc: Set filename for a block Ret: None Args: $filename Side_Effects: Die if no argument is used. Example: $rblock->set_command_file($filename);
Usage: $rblock->delete_command_file(); Desc: Delete command filename for a block and set command file as empty Ret: None Args: None Side_Effects: None Example: $rblock->delete_command_file();
Usage: my $filename = $rblock->get_result_file(); Desc: Get result filename of the block Ret: $filename, the result filename for the block associated to rbase. Args: None Side_Effects: None Example: my $filename = $rblock->get_result_file();
Usage: $rblock->set_result_file($filename); Desc: Set result filename for a block Ret: None Args: $filename, the result filename for the block associated to rbase. Side_Effects: Die if no argument is used or if the result file doesnt exist Example: $rblock->set_result_file($filename);
Usage: $rblock->delete_result_file(); Desc: Delete result filename for a block and set command file as empty Ret: None Args: None Side_Effects: None Example: $rblock->delete_result_file();
Usage: $rblock->add_command($r_command); Desc: Add a R command line to a block Ret: None Args: $r_command, a string or a hash ref. with the R commands. If hashref. is used, it will translated to R using r_var from R::YapRI::Interpreter::Perl Side_Effects: Die if no argument is used. Die if argument is not an scalar or an hash reference. Translate a perl hashref. to R command if hashref is used. Example: $rblock->add_command('x <- c(10, 9, 8, 5)') $rblock->add_command({ '' => { x => [10, 9, 8, 5] } })
Usage: my @commands = $rblock->read_commands(); Desc: Read all the R command lines from a block and return them in an array. Ret: @commands, an array with the commands used in the block Args: None Side_Effects: None Example: None
Usage: $rblock->run_block(); Desc: Run R commands for a specific block. Ret: None Args: None Side_Effects: None Example: $rblock->run_block();
Usage: my @results = $rblock->read_results(); Desc: Read all the results lines from a block and return them as an array. Ret: @results, an array with the produced by the block Args: None Side_Effects: None Example: my @results = $rblock->read_results();
Destructor will delete the files associated with this block (command and result) if the rbase switch keepfiles is disabled.
Usage: $block->DESTROY(); Desc: Destructor for block object. It also delete the command file and the result files associated with that block if keepfiles from rbase is disabled Ret: None Args: None Side_Effects: None Example: $block->DESTROY();
Lukas Mueller
Robert Buels
Naama Menda
Jonathan "Duke" Leto
Copyright 2011 Boyce Thompson Institute for Plant Research
Copyright 2011 Sol Genomics Network (solgenomics.net)
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install R::YapRI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm R::YapRI
CPAN shell
perl -MCPAN -e shell install R::YapRI
For more information on module installation, please visit the detailed CPAN module installation guide.