PerlスクリプトからRを起動する
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
COLOR(red){SIZE(30){PerlスクリプトからRを起動}}
#contents
~
*Perl 内部から R をバッチモードで実行 [#aea0de90]
以下の Perl スクリプトを数値引数 num で実行すると、log(nu...
########## Perl スクリプト ##########################
#!/usr/bin/perl
(($arg1) = @ARGV) || die "Must pass a numerical argument...
$script = "/tmp/rwrap$$.R";
open(SCRIPT, ">$script");
print SCRIPT <<EOF;
arg1 <- $arg1
options(error=expression(q(status=arg1)))
if (arg1 > 0) log(arg1)
q()
EOF
close(SCRIPT);
system("R --vanilla --slave < $script");
($Rstat = $?/256) && die "Aborted in R with status $Rsta...
unlink $script;
#####################################################
$ ./test.perl 2.0 # Unix のコンマンドラインから実行
[1] 0.6931472 # log(2.0)
実行結果を Perl の内部で受け取る方法は、以下の通り。
@array = `R --vanilla --slave < $script`; ## 行ごとの文...
$scalar = `R --vanilla --slave < $script`; ## 各行を結合...
*RSPerl の利用 [#n91292ff]
(そういうものがあるらしい。使ったことのある人の解説を期待)
インストールしてみましたが、下記のようなエラーが出ます。
環境:VineSeed+perl5.8.1+R1.7.0+RSPerl_0.5-7
$ PERLLIB=/usr/lib/R/library/RSPerl/share/lib/perl5/site...
thread-multi:/usr/lib/R/library/RSPerl/share/blib/lib pe...
1..1
Can't load '/usr/lib/R/library/RSPerl/share/lib/perl...
linux-thread-multi/auto/R/R.so' for module R: /usr/lib/R...
libPerlConverter.so: undefined symbol: R_GlobalEnv at
/usr/lib/perl5/5.8.1/i386-linux-thread-multi/DynaLoader....
at test.pl line 11
Compilation failed in require at test.pl line 11.
BEGIN failed--compilation aborted at test.pl line 11.
not ok 1
以下のようにインストールすれば、いちおうテストプログラム(...
R CMD INSTALL --configure-args='--with-in-perl' RSPerl_0...
export PERL5LIB=/usr/local/lib/R/library/RSPerl/perl:$PE...
source /usr/local/lib/R/library/RSPerl/scripts/RSPerl.bsh
でもやっぱりいくつかのプログラムが動きません。
RSPerl/inst/examples$ perl test4.pl
Can't locate object method "TIESCALAR" via package "RHas...
*PDL::R::math [#g8b98ed4]
Perl内からR関数を利用するモジュール
http://search.cpan.org/~cavanaugh/PDL-R-math-0.12/rmath.pd
-実行結果を Perl の内部で受け取る方法ですが, system() の...
#comment
* Perl から R を操作するモヂュール Statistics::R (2004.2....
r-help 記事を引用
-I have released the new module Statistics::R and need so...
status. This will permit the control of the the R (R-proj...
~
[[URLはここ:http://search.cpan.org/~gmpassos/Statistics-R...
* IPC::Open2 [#td5e43aa]
#!/usr/local/bin/perl -s
use strict;
use FileHandle;
use IPC::Open2;
use IPC::Open3;
if (1) {
my($fhr) = new FileHandle();
my($fhw) = new FileHandle();
my($fhe) = new FileHandle();
my($fhOld) = select($fhw); $| = 1; select($fhOld);
open2($fhr, $fhw, '/usr/bin/R', '--no-save');
# open3($fhw, $fhr, $fhe, '/usr/bin/R', '--no-save');
my($i);
for($i = 0; $i <= 10; $i++) {
# ↓もし ?n となっていたら ...
$fhw->print("1:($i*10)\n"); # ↓ここも同様
$fhw->print("print('EndOfCommands')\n"); # あと...
while($_ = $fhr->getline()) {
if (/"EndOfCommands"/) {
last; # R の処理が終了した
}
print;
}
}
exit(0);
}
終了行:
COLOR(red){SIZE(30){PerlスクリプトからRを起動}}
#contents
~
*Perl 内部から R をバッチモードで実行 [#aea0de90]
以下の Perl スクリプトを数値引数 num で実行すると、log(nu...
########## Perl スクリプト ##########################
#!/usr/bin/perl
(($arg1) = @ARGV) || die "Must pass a numerical argument...
$script = "/tmp/rwrap$$.R";
open(SCRIPT, ">$script");
print SCRIPT <<EOF;
arg1 <- $arg1
options(error=expression(q(status=arg1)))
if (arg1 > 0) log(arg1)
q()
EOF
close(SCRIPT);
system("R --vanilla --slave < $script");
($Rstat = $?/256) && die "Aborted in R with status $Rsta...
unlink $script;
#####################################################
$ ./test.perl 2.0 # Unix のコンマンドラインから実行
[1] 0.6931472 # log(2.0)
実行結果を Perl の内部で受け取る方法は、以下の通り。
@array = `R --vanilla --slave < $script`; ## 行ごとの文...
$scalar = `R --vanilla --slave < $script`; ## 各行を結合...
*RSPerl の利用 [#n91292ff]
(そういうものがあるらしい。使ったことのある人の解説を期待)
インストールしてみましたが、下記のようなエラーが出ます。
環境:VineSeed+perl5.8.1+R1.7.0+RSPerl_0.5-7
$ PERLLIB=/usr/lib/R/library/RSPerl/share/lib/perl5/site...
thread-multi:/usr/lib/R/library/RSPerl/share/blib/lib pe...
1..1
Can't load '/usr/lib/R/library/RSPerl/share/lib/perl...
linux-thread-multi/auto/R/R.so' for module R: /usr/lib/R...
libPerlConverter.so: undefined symbol: R_GlobalEnv at
/usr/lib/perl5/5.8.1/i386-linux-thread-multi/DynaLoader....
at test.pl line 11
Compilation failed in require at test.pl line 11.
BEGIN failed--compilation aborted at test.pl line 11.
not ok 1
以下のようにインストールすれば、いちおうテストプログラム(...
R CMD INSTALL --configure-args='--with-in-perl' RSPerl_0...
export PERL5LIB=/usr/local/lib/R/library/RSPerl/perl:$PE...
source /usr/local/lib/R/library/RSPerl/scripts/RSPerl.bsh
でもやっぱりいくつかのプログラムが動きません。
RSPerl/inst/examples$ perl test4.pl
Can't locate object method "TIESCALAR" via package "RHas...
*PDL::R::math [#g8b98ed4]
Perl内からR関数を利用するモジュール
http://search.cpan.org/~cavanaugh/PDL-R-math-0.12/rmath.pd
-実行結果を Perl の内部で受け取る方法ですが, system() の...
#comment
* Perl から R を操作するモヂュール Statistics::R (2004.2....
r-help 記事を引用
-I have released the new module Statistics::R and need so...
status. This will permit the control of the the R (R-proj...
~
[[URLはここ:http://search.cpan.org/~gmpassos/Statistics-R...
* IPC::Open2 [#td5e43aa]
#!/usr/local/bin/perl -s
use strict;
use FileHandle;
use IPC::Open2;
use IPC::Open3;
if (1) {
my($fhr) = new FileHandle();
my($fhw) = new FileHandle();
my($fhe) = new FileHandle();
my($fhOld) = select($fhw); $| = 1; select($fhOld);
open2($fhr, $fhw, '/usr/bin/R', '--no-save');
# open3($fhw, $fhr, $fhe, '/usr/bin/R', '--no-save');
my($i);
for($i = 0; $i <= 10; $i++) {
# ↓もし ?n となっていたら ...
$fhw->print("1:($i*10)\n"); # ↓ここも同様
$fhw->print("print('EndOfCommands')\n"); # あと...
while($_ = $fhr->getline()) {
if (/"EndOfCommands"/) {
last; # R の処理が終了した
}
print;
}
}
exit(0);
}
ページ名: