line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Statistics::embedR; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24264
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
435
|
use Statistics::useR; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.10.1"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
state $r = {}; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
|
|
|
|
|
|
return $r if ref $r ne "HASH"; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $that = shift; |
16
|
|
|
|
|
|
|
my $class = ref $that || $that; |
17
|
|
|
|
|
|
|
init_R; |
18
|
|
|
|
|
|
|
bless $r, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub DESTROY { |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
$self->quit("save='no'"); |
24
|
|
|
|
|
|
|
end_R; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub AUTOLOAD { |
28
|
|
|
|
|
|
|
my ($name) = our $AUTOLOAD =~ /::(\w+)$/; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $method = sub { |
31
|
|
|
|
|
|
|
my $self = shift; |
32
|
|
|
|
|
|
|
$name =~ s/_/./g; |
33
|
|
|
|
|
|
|
$self->R("$name(@_)"); |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
no strict 'refs'; |
37
|
|
|
|
|
|
|
*{ $AUTOLOAD } = $method; |
38
|
|
|
|
|
|
|
goto &$method; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub eval { |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
eval_R(join "\n", @_); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub load { |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
$self->library($_) for @_; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub R { |
52
|
|
|
|
|
|
|
my $self = shift; |
53
|
|
|
|
|
|
|
my $result = $self->eval(@_)->getvalue; |
54
|
|
|
|
|
|
|
my @keys = keys %$result; |
55
|
|
|
|
|
|
|
return $result unless @keys == 1; |
56
|
|
|
|
|
|
|
return $result unless $keys[0] ~~ ['int', 'str', 'real']; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $values = $result->{$keys[0]}; |
59
|
|
|
|
|
|
|
return @$values == 1 ? $values->[0] : $values; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub arry2R { |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
my ($src, $dest) = @_; |
65
|
|
|
|
|
|
|
Statistics::RData->new( |
66
|
|
|
|
|
|
|
data => {val => $src}, |
67
|
|
|
|
|
|
|
varname => $dest |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
$self->eval("$dest <- $dest\$val"); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; # End of Statistics::embedR |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |