Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed translated content for 'cs'
Sv translation
languageen

In BellaDati ML Studio it is possible to use R libraries and scripts. To be able to do that, BellaDati ML Studio needs to connect to running R-Serve instance.

Environment setup

The easiest way to setup the environment is to install R Studio and use it to start R-Serve.

  1. Download R Studio from official page and install it.
  2. Launch R Studio.
  3. Install R-Serve by using CRAN. Simply type this command to console:

    Code Block
    install.packages("Rserve")
  4. Activate the library by using this command:

    Code Block
    library(Rserve)
  5. Create the configuration file Rserv.cfg in the installation folder of R-Serve (e. g. C:\Users\username\Documents\R\win-library\3.3\Rserve). Add following parameters:

    Code Block
    remote enable
    port 6311
  6. Start R-Serve. In the start command, you have to specify path to the configuration file:

    Code Block
    Rserve(args="--RS-conf C:\\Users\\username\\DOCUME~1\\R\\WIN-LI~1\\3.3\\Rserve\\Rserv.cfg")
  7. Once R-Serve is running, you have to configure BellaDati ML Studio. Go to Settings and R-serve host (localhost in case it is running locally) and R-serve port (specified in Rserv.cfg). Save the settings.

  8. Now you are ready to start using R in BellaDati ML Studio.

Executing R Scripts

To execute R code, a special function executeR() is available in ML Studio. The script itself is placed between the parenthesis, enclosed in quotes. Below you can find simple example of adding two numbers in R:

Code Block
executeR('toString(2+3)')

Function toString() is used to get only the value itself.

For longer script, it is better to store them inside String variable and the execute the code by using this variable as parameter of the function executeR.

Code Block
String script= 'toString((3+4)*5)'
executeR(script)

It is also possible to read data from files or create temporary tables. To be able to read a file, first it has to be loaded to the ML script outside of the R code by using loadFile() function. Then it is possible to access the file as in standard R code, e. g. by using read.table()

Function paste() is used to create a table. This functions concatenates a special string --data--, which is used to markup the start and end of the table, and the content of the table itself. It is also possible define the header of the table, by adding a new line entity \\n and comma-separated list of column names after the first --data-- string.

Below you can find an example of creating a table with four columns. The content of the table is sum of all values for first four columns of an attached file.

Code Block
String script2= '''
externalData=read.table('DATA_4.03_MNT.csv', sep=',',header=TRUE)
a = "--data--\\nlifetime,broken,pressureInd,moistureInd"
paste(a,toString(colSums(externalData[,c(-5,-6,-7)])),a, sep = "\\n")
'''
loadFile('DATA_4.03_MNT.csv')
executeR(script2)

The result of the script is following:

You can also download sample ML project containing all three examples mentioned above. The file is compatible with BellaDati 2.8.6.3 and newer.

 

Sv translation
languagede

In BellaDati ML Studio ist es möglich, R-Bibliotheken und Skripte zu verwenden. Um dies zu erreichen, muss sich BellaDati ML Studio mit der laufenden R-Serve-Instanz verbinden.

Umgebungseinstellungen

Der einfachste Weg, die Umgebung einzurichten, besteht darin, R Studio zu installieren und damit R-Serve zu starten.

  1. Laden Sie R Studio von der offiziellen Seite herunter und installieren Sie es.
  2. Starten Sie R Studio.
  3. Installieren Sie R-Serve mit CRAN. Geben Sie einfach diesen Befehl in die Konsole ein:

    Code Block
    install.packages("Rserve")
  4. Aktivieren Sie die Bibliothek mit diesem Befehl:

    Code Block
    library(Rserve)
  5. Erstellen Sie die Konfigurationsdatei Rserv.cfg im Installationsordner von R-Serve (z. B. C:\Users\username\Dokumente\R\win-library\3.3\Rserve). Fügen Sie folgende Parameter hinzu:

    Code Block
    remote enable
    port 6311
  6. Starten Sie die R-Serve. Im Startbefehl müssen Sie den Pfad zur Konfigurationsdatei angeben:

    Code Block
    Rserve(args="--RS-conf C:\\Users\\username\\DOCUME~1\\R\\WIN-LI~1\\3.3\\Rserve\\Rserv.cfg")
  7. Sobald R-Serve läuft, müssen Sie BellaDati ML Studio konfigurieren. Gehen Sie zu Einstellungen und R-Serve Host (localhost, falls er lokal läuft) und R-Serve Port (angegeben in Rserv.cfg). Speichern Sie die Einstellungen.

  8. Jetzt sind Sie bereit, R in BellaDati ML Studio zu verwenden.

Ausführen von R-Skripten

Um R-Code auszuführen, steht im ML Studio eine spezielle Funktion executeR() zur Verfügung. Das Skript selbst befindet sich zwischen der Klammer, die in Anführungszeichen eingeschlossen ist. Nachfolgend finden Sie ein einfaches Beispiel für das Hinzufügen von zwei Zahlen in R:

Code Block
executeR('toString(2+3)')

Die Funktion toString() wird verwendet, um nur den Wert selbst zu erhalten.

Für längere Skripte ist es besser, sie in der String-Variablen zu speichern und den Code auszuführen, indem man diese Variable als Parameter der Funktion executeR verwendet.

Code Block
String script= 'toString((3+4)*5)'
executeR(script)

 

Es ist auch möglich, Daten aus Dateien zu lesen oder temporäre Tabellen zu erstellen. Um eine Datei lesen zu können, muss sie zunächst außerhalb des R-Codes mit dem Befehl loadFile() in das ML-Skript geladen werden. Dann ist es möglich, wie im Standard-R-Code auf die Datei zuzugreifen, z. B. mit read.table().

 

Die Funktion paste() wird verwendet, um eine Tabelle zu erstellen. Diese Funktion verknüpft eine spezielle Zeichenkette --data--, die verwendet wird, um den Anfang und das Ende der Tabelle sowie den Inhalt der Tabelle selbst zu markieren. Es ist auch möglich, den Header der Tabelle zu definieren, indem man eine neue Zeilenentität \\n und eine kommagetrennte Liste von Spaltennamen nach der ersten Zeichenkette --data-- hinzufügt.

Nachfolgend finden Sie ein Beispiel für das Erstellen einer Tabelle mit vier Spalten. Der Inhalt der Tabelle ist die Summe aller Werte für die ersten vier Spalten einer angehängten Datei.

Code Block
String script2= '''
externalData=read.table('DATA_4.03_MNT.csv', sep=',',header=TRUE)
a = "--data--\\nlifetime,broken,pressureInd,moistureInd"
paste(a,toString(colSums(externalData[,c(-5,-6,-7)])),a, sep = "\\n")
'''
loadFile('DATA_4.03_MNT.csv')
executeR(script2)

Das Ergebnis des Skripts ist folgendes:

The file is compatible with BellaDati 2.8.6.3 and newer. Sie können auch ein Muster-ML-Projekt herunterladen, das alle drei oben genannten Beispiele enthält. Die Datei ist kompatibel mit BellaDati 2.8.6.3 und neuer.

 

Sv translation
languageja

BellaDati ML Studioでは、Rライブラリとスクリプトを使用できます。それを可能にするには、BellaDati ML Studioは実行中のR-Serveインスタンスに接続する必要があります。

環境設定

環境を設定する最も簡単な方法は、R Studioをインストールし、それを使用してR-Serveを起動することです。

  1. 公式ページからR Studioをダウンロードしてインストールします。
  2. R Studioを起動します。
  3. CRANを使用してR-Serveをインストールします。コンソールにこのコマンドを入力するだけです:

    Code Block
    install.packages("Rserve")
  4. 次のコマンドを使用して、ライブラリをアクティブにします:

    Code Block
    library(Rserve)
  5. R-Serveのインストールフォルダーに構成ファイルRserv.cfgを作成します(例: C:\Users\username\Documents\R\win-library\3.3\Rserve)。以下のパラメーターを追加します。

    Code Block
    remote enable
    port 6311
  6. R-Serveを開始します。 startコマンドで、構成ファイルへのパスを指定する必要があります:

    Code Block
    Rserve(args="--RS-conf C:\\Users\\username\\DOCUME~1\\R\\WIN-LI~1\\3.3\\Rserve\\Rserv.cfg")
  7. R-Serveを実行したら、BellaDati ML Studioを構成する必要があります。設定でR-serve host(ローカルで実行されている場合はlocalhost)とR-serve portRserv.cfgで指定)に移動します。設定を保存します。

  8. これで、BellaDati ML StudioでRを使用する準備が整いました。

Rスクリプトの実行

Rコードを実行するために、ML Studioで特別なexecuteR()関数を使用できます。スクリプト自体は、引用符で囲まれた括弧の間に配置されます。以下に、Rに2つの数値を追加する簡単な例を示します:

Code Block
executeR('toString(2+3)')

toString()関数は、値自体のみを取得するために使用されます。

長いスクリプトの場合、文字列変数内に保存し、この変数をexecuteR関数のパラメーターとして使用してコードを実行することをお勧めします。

Code Block
String script= 'toString((3+4)*5)'
executeR(script)

ファイルからデータを読み取ったり、一時テーブルを作成したりすることもできます。ファイルを読み取るには、まずloadFile()関数を使用して、Rコードの外部のMLスクリプトにロードする必要があります。その後、標準のRコードのようにファイルにアクセスできます。 例: read.table()の使用により。

paste()関数は、テーブルを作成するために使用されます。この関数は、テーブルの開始と終了、テーブル自体のコンテンツをマークアップするために使用される特別な文字--data--を連結します。最初の--data--文字列の後に改行エンティティ\\nと列名のコンマ区切りリストを追加することにより、テーブルのヘッダーを定義することもできます。
以下に、4つの列を持つテーブルを作成する例を示します。テーブルの内容は、添付ファイルの最初の4列のすべての値の合計です。

Code Block
String script2= '''
externalData=read.table('DATA_4.03_MNT.csv', sep=',',header=TRUE)
a = "--data--\\nlifetime,broken,pressureInd,moistureInd"
paste(a,toString(colSums(externalData[,c(-5,-6,-7)])),a, sep = "\\n")
'''
loadFile('DATA_4.03_MNT.csv')
executeR(script2)

スクリプトの結果は以下の通りです:

上記の3つの例をすべて含むサンプルMLプロジェクトをダウンロードすることもできます。このファイルはBellaDati 2.8.6.3以降と互換性があります。