あなたはScalaの中からR(ライブラリ)を使用して、Rと ScalaのRを使い、RからScalaを呼び出す?
- のpossibilitesについて何かを知っていますか?
敬具
ラファエル
あなたはScalaの中からR(ライブラリ)を使用して、Rと ScalaのRを使い、RからScalaを呼び出す?
敬具
ラファエル
直接Scalaのインタフェースがある場合、私は知らないが、rJava http://www.rforge.net/rJava/は役立つはずです。
JRI。それがもはや動作するかどうかはわかりません。それはJRIを包み込む小さなDSLでした。おそらくマクロなどが今より良くなる可能性があります。
https://github.com/hughleat/scala2R
のために何をしている可能性がありますされ
CRANのRでjvmr packageをチェックしてください。それはあなたがすることができます:
をScalaのインタプリタ/コンパイラを埋め込む埋め込みます。その使用法を説明する記事はhereです。 (公開:私は作者です。)
非常に役に立ちます。私はトレリス/ラティスグラフィックス/プロットにきれいなScalaアダプタを作成するためにこれを使用する人がいるのが好きです。 JFreeChart、JMathPlotなどを忘れて、Rプロットが勝利です! – metasim
@David:このポストをありがとう。それは非常に有用だったと私は正常にスカラで働いているR通訳を得ることができましたが、私はスカラーのようないくつかのR関数を使用する方法についてはよくわかりません(スキャン、laply..etcのような) plyrやscalaの他のツールのようなライブラリを追加する。どんな助けでも大歓迎です。 – Pawan
@Pawan私も、私はRライブラリを追加する方法を知りたいと思います。あなたは解決策を見つけましたか? –
私はjvmrを使ってこれを達成できました。以下のコードは、私がscalaコンソールから実行しているapache sparkアプリケーションのサンプルです。
package org.scala.rtest
import org.ddahl.jvmr.RInScala
object RIntegration {
def main(args: Array[String]) {
val R = RInScala()
R>"""
require(sparkR)
score.sentiment = function(sentences, pos.words, neg.words, .progress='none')
{
require(plyr)
require(stringr)
scores = laply(sentences, function(sentence, pos.words, neg.words) {
# clean up sentences with R's regex-driven global substitute, gsub():
sentence = gsub('[[:punct:]]', '', sentence, ignore.case=T)
sentence = gsub('[[:cntrl:]]', '', sentence, ignore.case=T)
sentence = gsub('\\d+', '', sentence, ignore.case=T)
# and convert to lower case:
sentence = tolower(sentence)
# split into words. str_split is in the stringr package
word.list = str_split(sentence, '\\s+')
# sometimes a list() is one level of hierarchy too much
words = unlist(word.list)
# compare our words to the dictionaries of positive & negative terms
pos.matches = match(words, pos.words)
neg.matches = match(words, neg.words)
# match() returns the position of the matched term or NA
# we just want a TRUE/FALSE:
pos.matches = !is.na(pos.matches)
neg.matches = !is.na(neg.matches)
# and conveniently enough, TRUE/FALSE will be treated as 1/0 by sum():
score = sum(pos.matches) - sum(neg.matches)
return(score)
}, pos.words, neg.words, .progress=.progress)
scores.df = data.frame(score=scores, text=sentences)
return(scores.df)
}
"""
R(" x <- scan('positive-words.txt',what='character',comment.char=';')")
R(" y <- scan('negative-words.txt',what='character',comment.char=';')")
R(" z <- scan('twitterstream1.txt', what='character')")
R.eval("df <- score.sentiment(z,x,y)")
println(R.capture("df"))
}
}
希望します。
「rscala」と呼ばれるこの目的のために、CRANにはRパッケージがあります。これは、コールバック(例えば、Rから呼び出されたScalaコードからRにコールバックする)と同様に、双方向呼び出し(ScalaからのRとRからのScala)とコールバックを可能にします。それはwell documentedです。このパッケージは、別の答えに記載されている "jvmr"パッケージを置き換えます。
便宜のためのCRANリンク:https://cran.r-project.org/web/packages/rscala/ – michael
こんにちは。 1つの方法は、おそらくこのような状況に特有のものではなく、安らかなサービスを使用することです。しかし、Rでは、他の救済型サービスにアクセスし、安静型サービスを提供することはできません。したがって、httpのPUTとDELETEをサポートするRのhttpパッケージ(またはlib)が必要になります。 Rデータ構造をXMLにシリアライズして(どちらが忘れてしまったのか)簡単になるパッケージがあります。 httpパッケージ用のポインタはありますか?私はhttml GET用のR.rspパッケージが好きですが、PUTとDELETEには何を使用するのですか?最終目標は、Rとhaskellを組み合わせることです。 – mrsteve