@@ -11,53 +11,34 @@ my $rserve_loaded = eval {
1111sub access {
1212 die ' Statistics::R::IO::Rserve could not be loaded. Have you installed the module?'
1313 unless $rserve_loaded ;
14-
15- Statistics::R::IO::Rserve-> new(@_ );
14+ return Statistics::R::IO::Rserve-> new(@_ );
1615}
1716
18- # # Evaluates an R expression guarding it inside an R `try` function
19- # #
20- # # Returns the result as a REXP if no exceptions were raised, or
21- # # `die`s with the text of the exception message.
17+ # Evaluates an R expression guarding it inside an R `try` function
18+ #
19+ # Returns the result as a REXP if no exceptions were raised, or
20+ # `die`s with the text of the exception message.
2221sub try_eval {
2322 my ($rserve , $query ) = @_ ;
2423
25- my $result = $rserve -> eval (" try({ $query }, silent=TRUE)" );
26- die $result -> to_pl-> [0] if _inherits($result , ' try-error' );
27- # die $result->to_pl->[0] if $result->inherits('try-error');
24+ my $result = $rserve -> eval (" try({ $query }, silent = TRUE)" );
25+ die $result -> to_pl-> [0] if $result -> inherits(' try-error' );
2826
29- $result ;
27+ return $result ;
3028}
3129
32- # # Returns a REXP's Perl representation, dereferencing it if it's an
33- # # array reference
34- # #
35- # # `REXP::to_pl` returns a string scalar for Symbol, undef for Null,
36- # # and an array reference to contents for all vector types. This
37- # # function is a utility wrapper to make it easy to assign a Vector's
38- # # representation to an array variable, while still working sensibly
39- # # for non-arrays.
30+ # Returns a REXP's Perl representation, dereferencing it if it's an
31+ # array reference
32+ #
33+ # `REXP::to_pl` returns a string scalar for Symbol, undef for Null,
34+ # and an array reference to contents for all vector types. This
35+ # function is a utility wrapper to make it easy to assign a Vector's
36+ # representation to an array variable, while still working sensibly
37+ # for non-arrays.
4038sub unref_rexp {
41- my $rexp = shift ;
42-
39+ my $rexp = shift ;
4340 my $value = $rexp -> to_pl;
44- if (ref ($value ) eq ref ([])) {
45- @{$value };
46- } else {
47- $value ;
48- }
49- }
50-
51- # # Reimplements method C<inherits> of class L<Statistics::R::REXP>
52- # # until I figure out why calling it directly doesn't work in the safe
53- # # compartment
54- sub _inherits {
55- my ($rexp , $class ) = @_ ;
56-
57- my $attributes = $rexp -> attributes;
58- return unless $attributes && $attributes -> {' class' };
59-
60- grep {/ ^$class $ / } @{ $attributes -> {' class' }-> to_pl };
41+ return ref ($value ) eq ' ARRAY' ? @$value : $value ;
6142}
6243
63441;
0 commit comments