0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Ruby, R】RserveをRubyから起動・終了する

Last updated at Posted at 2025-12-21

R側の準備

Rserveパッケージを予めインストールしておきます。

install.packages("Rserve", dependencies = T)

Ruby側の準備

rserveクライアントを予めインストールしておきます。

gem install rserve-client

プログラム中に

program1.rb
require "rserve"
class Fixnum < Integer; end
autoload(:Matrix, "matrix")

2行目はFixnumが廃止されたのでその対策。
3行目もあった方が良さそうです。

Rserveの起動

rs=Rserve::Connection.new()

内部では R CMD Rserve で起動していますが、Rserveの位置が標準と異なっている場合はエラーになります。もしエラーが出るようでしたら

rs=Rserve::Connection.new(cmd_init: "Rscript --vanilla -e 'library(Rserve);Rserve()'")

を試してみてください。(macOSでRのサイトからダウンロードしたインストーラの場合はこちらで)

Rserveの終了

rs.shutdown
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?