NAME
R::YapRI::Block.pm
A module to segment the R commands.
SYNOPSIS
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();
DESCRIPTION
A wrapper to use blocks with R::YapRI::Base.
Use blocks through rbase object.
AUTHOR
Aureliano Bombarely <ab782@cornell.edu>
CLASS METHODS
The following class methods are implemented:
(*) CONSTRUCTORS:
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.
constructor new
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'
);
(*) ACCESSORS:
No set accessors have been created for rbase or blockname. They are controlled by R::YapRI::Base object.
get_rbase
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();
get_blockname
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();
get_command_file
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();
set_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
);
delete_command_file
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();
get_result_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();
set_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
);
delete_result_file
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();
(*) COMMAND METHODS:
add_command
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] } })
read_commands
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
run_block
Usage:
$rblock
->run_block();
Desc: Run R commands
for
a specific block.
Ret: None
Args: None
Side_Effects: None
Example:
$rblock
->run_block();
read_results
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();
(*) DESTRUCTORS:
Destructor will delete the files associated with this block (command and result) if the rbase switch keepfiles is disabled.
DESTROY
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();
ACKNOWLEDGEMENTS
Lukas Mueller
Robert Buels
Naama Menda
Jonathan "Duke" Leto
COPYRIGHT AND LICENCE
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.