Generate new dataframe with Execute R

lulu_yang
lulu_yang New Altair Community Member
edited November 2024 in Community Q&A

Hi,

 

I am new to RM and tried to use Execute R to apply KS-test and return its result, which is a dataframe. When I ran my process, it shows "Process failed. Script terminated abnormally":

  • Exception: com.rapidminer.operator.OperatorException
  • Message: Script terminated abnormally.
  • Stack trace:
  • com.rapidminer.extension.rscripting.operator.scripting.AbstractScriptRunner.run(AbstractScriptRunner.java:166)
  • com.rapidminer.extension.rscripting.operator.scripting.AbstractScriptingLanguageOperator.doWork(AbstractScriptingLanguageOperator.java:90)
  • com.rapidminer.extension.rscripting.operator.scripting.r.RScriptingOperator.doWork(RScriptingOperator.java:73)
  • com.rapidminer.operator.Operator.execute(Operator.java:1004)
  • com.rapidminer.operator.execution.SimpleUnitExecutor.execute(SimpleUnitExecutor.java:77)
  • com.rapidminer.operator.ExecutionUnit$3.run(ExecutionUnit.java:812)
  • com.rapidminer.operator.ExecutionUnit$3.run(ExecutionUnit.java:807)
  • java.security.AccessController.doPrivileged(Native Method)
  • com.rapidminer.operator.ExecutionUnit.execute(ExecutionUnit.java:807)
  • com.rapidminer.operator.OperatorChain.doWork(OperatorChain.java:428)
  • com.rapidminer.operator.Operator.execute(Operator.java:1004)
  • com.rapidminer.Process.execute(Process.java:1310)
  • com.rapidminer.Process.run(Process.java:1285)
  • com.rapidminer.Process.run(Process.java:1176)
  • com.rapidminer.Process.run(Process.java:1129)
  • com.rapidminer.Process.run(Process.java:1124)
  • com.rapidminer.Process.run(Process.java:1114)
  • com.rapidminer.gui.ProcessThread.run(ProcessThread.java:65)

I can run the example code without similar problem and if I deleted the last two lines - "ks.table<-as.data.table(ks.table)
return(ks.table)". It is fine as well...

 

Here is my XML.:

<?xml version="1.0" encoding="UTF-8"?><process version="8.1.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="8.1.000" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="retrieve" compatibility="8.1.000" expanded="true" height="68" name="Retrieve Golf" width="90" x="45" y="34">
<parameter key="repository_entry" value="//Samples/data/Golf"/>
</operator>
<operator activated="true" class="r_scripting:execute_r" compatibility="8.1.000" expanded="true" height="82" name="Execute R (2)" width="90" x="246" 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;library(dplyr)&#10;library(data.table)&#10;&#10;columnname&lt;-c()&#10;&#10;###Save the column name and label name:&#10;for(i in seq(along = metaData$data)){&#10;&#9;columnname&lt;-c(columnname, names(metaData$data)[i])&#10;&#9;&#10;&#9;if (metaData$data[[i]]$role == 'label'){&#10;&#9;labelname&lt;- names(metaData$data)[i]&#10;&#9;}&#10;}&#10;&#10;### apply filter based on the label:&#10;expyes&lt;-lazyeval::interp(quote(x == y), x=as.name(labelname), y = &quot;yes&quot;)&#10;expno&lt;-lazyeval::interp(quote(x == y), x=as.name(labelname), y = &quot;no&quot;)&#10;&#10;yes&lt;- filter_(data, expyes)&#10;no&lt;- filter_(data, expno)&#10;&#10;ks.table&lt;-data.frame()&#10;&#10;for(i in seq(along = metaData$data)){&#10;&#9;if ((metaData$data[[i]]$role == 'label') | (metaData$data[[i]]$type != &quot;Integer&quot;) ) next&#10;&#9;&#10;&#9;cyes&lt;-select(yes, select = names(metaData$data)[i])&#10;&#9;cno&lt;- select(no, select = names(metaData$data)[i])&#10;&#9;ks&lt;-ks.test(cyes, cno)&#10;&#9;row&lt;-data.frame(names(metaData$data)[i], ks$statistic,ks$p.value)&#10;&#9;print(as.character(row))&#10;&#9;ks.table&lt;-rbind(ks.table, row)&#10;}&#10;ks.table&lt;-as.data.table(ks.table)&#10;return(ks.table)&#10;}&#10;"/>
</operator>
<connect from_op="Retrieve Golf" from_port="output" to_op="Execute R (2)" to_port="input 1"/>
<connect from_op="Execute R (2)" from_port="output 1" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="source_input 2" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>

Does anyone have idea why it happens? Thanks for help!

 

Tagged:

Best Answer

  • earmijo
    earmijo New Altair Community Member
    Answer ✓

    In the R code you keep making reference to the object metaData that has never been defined. Try the code in R first and see if it runs.

Answers

  • earmijo
    earmijo New Altair Community Member
    Answer ✓

    In the R code you keep making reference to the object metaData that has never been defined. Try the code in R first and see if it runs.

  • lulu_yang
    lulu_yang New Altair Community Member

    Thank you @earmijo! It was my coding problem... Wrong data types have been delivered to ks.test() function.

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.