🎉 🎉 RAPIDMINER 9.10 IS OUT!!! 🎉🎉

Download the latest version helping analytics teams accelerate time-to-value for streaming and IIOT use cases.

CLICK HERE TO DOWNLOAD

import matlab with R Script, no output..

Fred12Fred12 Member Posts: 344   Unicorn
edited November 2018 in Help

hi,

I want to loop trough a directory with matlab files in it. I do it with R.matlab package in a R script. 

I want to import every file and output it as an Example set (data table) and pass it to a collection operator.

however, I am not able to get an Example set of the data table as output... why is this?

 

my process looks like:

<?xml version="1.0" encoding="UTF-8"?><process version="7.3.001">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="7.3.001" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="loop_files" compatibility="7.3.001" expanded="true" height="82" name="Loop Files" width="90" x="45" y="34">
<parameter key="directory" value="C:\Users\Admin\Desktop\matlab"/>
<process expanded="true">
<operator activated="true" breakpoints="after" class="r_scripting:execute_r" compatibility="7.2.000" expanded="true" height="82" name="Execute R" width="90" x="179" y="34">
<parameter key="script" value="# rm_main is a mandatory function, &#10;# the number of arguments has to be the number of input ports (can be none)&#10;rm_main = function(data)&#10;{&#10; &#9;if(&quot;xlsx&quot; %in% rownames(installed.packages()) == FALSE) {install.packages(&quot;xlsx&quot;)}&#10; &#9;if(&quot;R.matlab&quot; %in% rownames(installed.packages()) == FALSE) {install.packages(&quot;R.matlab&quot;)}&#10;&#9;library(xlsx)&#10;&#9;library(R.matlab)&#10;&#9;&#10; &#9;setwd(&quot;C:/Users/Admin/Desktop&quot;)&#10; &#10; # read in your matlab file&#10;&#9;matfile &lt;- readMat(data)&#10;&#10;&#9;# write into Excel file&#10;&#9;excelfile &lt;- write.xlsx(matfile, &quot;PathToExcelFile.xlsx&quot;, sheetName=&quot;1&quot;, col.names=TRUE, row.names = TRUE, append = FALSE, showNA=TRUE)&#10;&#10;&#9;o &lt;- as.data.frame(matfile)&#10; # connect 2 output ports to see the results&#10; print(head(o))&#10; &#10; return(o)&#10;}&#10;"/>
</operator>
<operator activated="true" class="collect" compatibility="7.3.001" expanded="true" height="82" name="Collect" width="90" x="313" y="34"/>
<connect from_port="file object" to_op="Execute R" to_port="input 1"/>
<connect from_op="Execute R" from_port="output 1" to_op="Collect" to_port="input 1"/>
<connect from_op="Collect" from_port="collection" to_port="out 1"/>
<portSpacing port="source_file object" spacing="0"/>
<portSpacing port="source_in 1" spacing="0"/>
<portSpacing port="sink_out 1" spacing="0"/>
<portSpacing port="sink_out 2" spacing="0"/>
</process>
</operator>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
</process>
</operator>
</process>

maybe I could also write it as excel file back on some folder and pass the path as a macro to some read excel operator afterwards? and then just read the excel file as usual with the "read excel" operator and the macro...?

but I prefer the direct way as an example set... anybody got an idea why the output does not work?

 

my 2nd question is: 

Is there any way to avoid loading the libraries once again every time the loop is executed? I would like to load them once for all the loops...

Sign In or Register to comment.