@@ -11,53 +11,34 @@ my $rserve_loaded = eval {
11
11
sub access {
12
12
die ' Statistics::R::IO::Rserve could not be loaded. Have you installed the module?'
13
13
unless $rserve_loaded ;
14
-
15
- Statistics::R::IO::Rserve-> new(@_ );
14
+ return Statistics::R::IO::Rserve-> new(@_ );
16
15
}
17
16
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.
22
21
sub try_eval {
23
22
my ($rserve , $query ) = @_ ;
24
23
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' );
28
26
29
- $result ;
27
+ return $result ;
30
28
}
31
29
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.
40
38
sub unref_rexp {
41
- my $rexp = shift ;
42
-
39
+ my $rexp = shift ;
43
40
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 ;
61
42
}
62
43
63
44
1;
0 commit comments