回答編集履歴
2
実行環境を追記
test
CHANGED
@@ -15,6 +15,16 @@
|
|
15
15
|
---
|
16
16
|
|
17
17
|
1つ目のサンプルを試しました。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
実行環境
|
22
|
+
|
23
|
+
OS: OSX Yosemite
|
24
|
+
|
25
|
+
php: 5.5.29
|
26
|
+
|
27
|
+
R: 3.1.0
|
18
28
|
|
19
29
|
|
20
30
|
|
1
サンプルのコードと実行結果を追加
test
CHANGED
@@ -11,3 +11,145 @@
|
|
11
11
|
1つ目のリンクの方法で実現できそうです。
|
12
12
|
|
13
13
|
2つ目のリンクではRが生成する画像を出力できるようです。
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
1つ目のサンプルを試しました。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
Rのコンソールで実行
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
> install.packages('rjson')
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
sample.R
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
library('rjson')
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
x1 <- commandArgs()[5]
|
40
|
+
|
41
|
+
x2 <- commandArgs()[6]
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
xx1 <- fromJSON(x1)
|
46
|
+
|
47
|
+
xx2 <- fromJSON(x2)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
cat(toJSON(c(xx1,xx2)))
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
sample.php
|
58
|
+
|
59
|
+
```php
|
60
|
+
|
61
|
+
<?php
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
$param = array('spam' => array(10,20), 'pan' => array(100,200));
|
66
|
+
|
67
|
+
$encParam = json_encode($param);
|
68
|
+
|
69
|
+
$param2 = array('bacon' => array(30,40), 'egg' => array(32.2,12.5));
|
70
|
+
|
71
|
+
$encParam2 = json_encode($param2);
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
$cmd = "R --vanilla --slave --args '$encParam' '$encParam2' < sample.R";
|
76
|
+
|
77
|
+
//print_r($cmd);
|
78
|
+
|
79
|
+
exec($cmd, $response);
|
80
|
+
|
81
|
+
$res = $response[0];
|
82
|
+
|
83
|
+
//print_r($res);
|
84
|
+
|
85
|
+
print_r(json_decode($res));
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
実行結果
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
$ php sample.php
|
96
|
+
|
97
|
+
警告メッセージ:
|
98
|
+
|
99
|
+
パッケージ ‘rjson’ はバージョン 3.1.2 の R の下で造られました
|
100
|
+
|
101
|
+
stdClass Object
|
102
|
+
|
103
|
+
(
|
104
|
+
|
105
|
+
[spam] => Array
|
106
|
+
|
107
|
+
(
|
108
|
+
|
109
|
+
[0] => 10
|
110
|
+
|
111
|
+
[1] => 20
|
112
|
+
|
113
|
+
)
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
[pan] => Array
|
118
|
+
|
119
|
+
(
|
120
|
+
|
121
|
+
[0] => 100
|
122
|
+
|
123
|
+
[1] => 200
|
124
|
+
|
125
|
+
)
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
[bacon] => Array
|
130
|
+
|
131
|
+
(
|
132
|
+
|
133
|
+
[0] => 30
|
134
|
+
|
135
|
+
[1] => 40
|
136
|
+
|
137
|
+
)
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
[egg] => Array
|
142
|
+
|
143
|
+
(
|
144
|
+
|
145
|
+
[0] => 32.2
|
146
|
+
|
147
|
+
[1] => 12.5
|
148
|
+
|
149
|
+
)
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
)
|
154
|
+
|
155
|
+
```
|