R script terminated anormally
I am trying to run a simple R script to gather data using the dplyr package, which is installed in my R sintallation I get the message that the script terminated abnormally. The full error:
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:1025)
com.rapidminer.operator.execution.SimpleUnitExecutor.execute(SimpleUnitExecutor.java:77)
com.rapidminer.operator.ExecutionUnit$2.run(ExecutionUnit.java:812)
com.rapidminer.operator.ExecutionUnit$2.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:1025)
com.rapidminer.Process.execute(Process.java:1315)
com.rapidminer.Process.run(Process.java:1290)
com.rapidminer.Process.run(Process.java:1181)
com.rapidminer.Process.run(Process.java:1134)
com.rapidminer.Process.run(Process.java:1129)
com.rapidminer.Process.run(Process.java:1119)
com.rapidminer.gui.ProcessThread.run(ProcessThread.java:65)
R script:
# rm_main is a mandatory function,
# the number of arguments has to be the number of input ports (can be none)
rm_main = function(data)
{
# your code goes here
library(dplyr)
data_long <- gather(data, stage, avg_weeks, average(lodgedCouncilToCertification_Weeks): average(SOCToRegistration_Weeks), factor_key=TRUE)
# connect output port to see the results
return(data_long)
}
Best Answer
-
Hi @kcallan,
gather() function may return a regular table or return a tibble table, which is a data frame with some minor variations from the base class
For tibble, if you need to view the result table in result view, it needs to be converted as data table.
I donot have your input data, but here is an exmple integration
<?xml version="1.0" encoding="UTF-8"?><process version="9.0.000-BETA4">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="9.0.000-BETA4" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="r_scripting:execute_r" compatibility="8.1.000" expanded="true" height="103" name="Execute R" width="90" x="179" y="30">
<parameter key="script" value="rm_main = function() { 	library(tidyr) 	library(dplyr) 	stocks <- tibble( 	time = as.Date('2009-01-01') + 0:9, 	X = rnorm(10, 0, 1), 	Y = rnorm(10, 0, 2), 	Z = rnorm(10, 0, 4) ) 	result <- as.data.frame(tib <- gather(stocks, stock, price, -time)) 	result$time <- as.character(result$time) 	return(list(tib,result)) } "/>
</operator>
<connect from_op="Execute R" from_port="output 1" to_port="result 1"/>
<connect from_op="Execute R" from_port="output 2" to_port="result 2"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
<portSpacing port="sink_result 3" spacing="0"/>
</process>
</operator>
</process>2
Answers
-
Hi @kcallan,
gather() function may return a regular table or return a tibble table, which is a data frame with some minor variations from the base class
For tibble, if you need to view the result table in result view, it needs to be converted as data table.
I donot have your input data, but here is an exmple integration
<?xml version="1.0" encoding="UTF-8"?><process version="9.0.000-BETA4">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="9.0.000-BETA4" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="r_scripting:execute_r" compatibility="8.1.000" expanded="true" height="103" name="Execute R" width="90" x="179" y="30">
<parameter key="script" value="rm_main = function() { 	library(tidyr) 	library(dplyr) 	stocks <- tibble( 	time = as.Date('2009-01-01') + 0:9, 	X = rnorm(10, 0, 1), 	Y = rnorm(10, 0, 2), 	Z = rnorm(10, 0, 4) ) 	result <- as.data.frame(tib <- gather(stocks, stock, price, -time)) 	result$time <- as.character(result$time) 	return(list(tib,result)) } "/>
</operator>
<connect from_op="Execute R" from_port="output 1" to_port="result 1"/>
<connect from_op="Execute R" from_port="output 2" to_port="result 2"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
<portSpacing port="sink_result 3" spacing="0"/>
</process>
</operator>
</process>2 -
I would like to add that where you print something in any of the script operators, it gets printed to the process log. I think it is one of the best ways to debug from RapidMiner studio.
Regards,
Sebastian
1