"R script does not provide results if init library in script"
B_
New Altair Community Member
I've developed a script in R and am trying to get it to run in RM.
I don't get any output and it seems to be related to initializing the R library I need (psych). The results are Unknown R type. If I comment out the library as in this example, the script output is delivered to RM. Psych is already installed in R.
RM is up to date and I'm using Win 7 x64, R 2.12.
I don't get any output and it seems to be related to initializing the R library I need (psych). The results are Unknown R type. If I comment out the library as in this example, the script output is delivered to RM. Psych is already installed in R.
RM is up to date and I'm using Win 7 x64, R 2.12.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.1.003">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.1.003" expanded="true" name="Process">
<process expanded="true" height="431" width="614">
<operator activated="false" class="read_csv" compatibility="5.1.003" expanded="true" height="60" name="Read CSV" width="90" x="45" y="75">
<parameter key="csv_file" value="d:\Data\test_pca_data-rm.txt"/>
<parameter key="column_separators" value="\t"/>
<parameter key="use_quotes" value="false"/>
<list key="annotations"/>
<list key="data_set_meta_data_information"/>
</operator>
<operator activated="false" class="r:export_data" compatibility="5.1.002" expanded="true" height="60" name="Export Example Set" width="90" x="227" y="86"/>
<operator activated="false" class="normalize" compatibility="5.1.003" expanded="true" height="94" name="Normalize" width="90" x="112" y="300"/>
<operator activated="true" class="r:execute_script_r" compatibility="5.1.002" expanded="true" height="76" name="Execute Script (R)" width="90" x="313" y="255">
<parameter key="script" value="##library(psych) dataout <- as.data.frame(9) x <- 5 y <- 23 z <- x * y dataout <- z "/>
<enumeration key="inputs"/>
<list key="results">
<parameter key="dataout" value="Generic R Result"/>
</list>
</operator>
<connect from_op="Execute Script (R)" from_port="output 1" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
0
Answers
-
That's strange. Your script ran fine for me (XP64, R-2.12.1), getting the same result whether library(psych) was commented out or not..
Are there multiple versions of R installed on that machine? Is is possible that the psych package isn't installed in the R installation that RM is accessing?
Keith
0 -
Thanks for the info Keith.
I tired XP64 and R 2.12.2 and the script works correctly commented out or not. I tried the psych library on two Win7 machines and it failed on both of them when library(psych) was uncommented.
0 -
Strange. I don't have a Win7 box to test it on at the moment, so not sure what the differences would be.
Pardon the really obvious questions, but just to make sure we're not overlooking something silly,,,
1) Does the script work when you run it in standalone R on the same Win7 machines?
2) There are no other versions of R installed on those machines?
3) Have you gotten a very basic R script to work in RM (i.e. one that loads no external libraries).
4) Are R and RM both either 32-bit or 64-bit (but not mixed where one is 32 bit and the other is 64 bit)?
Keith
0 -
I developed the script first in R then moved it to RM. Narrowed it down to the library being called. Basic scripts in win 7 that don't call the library work -
library(igraph) fails while ##library(igraph) generates an output.
All 3 machines are running 64 bit R 12.2 with common RHOME, x64 paths, etc.
0 -
Hi,
I'm quite confused now: What was the final diagnosis? Does it work? Doesn't it? Depending on what?
Greetings,
Sebastian0 -
I think B. is still having problems. But it sounds like the script works in standalone R on the same machine where it's failing in RM, which eliminates a bunch of the possible causes I had in mind.0
-
Sebastian,
The R script did not run under Windows 7 unless I commented out library(psych) -i.e., ## library(psych). I also tried it with the igraph library. It returns an unknown R type.
It does work correctly under XP.
Install a R library, then try this script in a R Execute Script operator. Set Results/Edit List to x, as a generic R output.
library(libname)
x <- 5
output: R Result
No Description available: Unknown R Type
then try
##library(libname)
x <- 5
output: R Result
[1] 5
The full script I created works correctly in R on Win 7 and XP and in RM on XP, but fails in RM on Win 7.
B.
0 -
OK, I just installed R 2.12-2 (x64) and RM 5.1.004 (x64) on my Window 7 Ultimate (x64) box at home.
I ran the following process. Note that I added a print(search()) to show which packages were loaded:<?xml version="1.0" encoding="UTF-8" standalone="no"?>
It appears to have worked for me. In the results view, I see a Generic R Result with the value of 115. I don't see anything about an Unknown R type.
<process version="5.1.004">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.1.004" expanded="true" name="Process">
<process expanded="true" height="431" width="614">
<operator activated="false" class="read_csv" compatibility="5.1.004" expanded="true" height="60" name="Read CSV" width="90" x="45" y="75">
<parameter key="csv_file" value="d:\Data\test_pca_data-rm.txt"/>
<parameter key="column_separators" value="\t"/>
<parameter key="use_quotes" value="false"/>
<list key="annotations"/>
<list key="data_set_meta_data_information"/>
</operator>
<operator activated="false" class="dummy" compatibility="5.1.004" expanded="true" height="60" name="Export Example Set" width="90" x="227" y="86"/>
<operator activated="false" class="normalize" compatibility="5.1.004" expanded="true" height="94" name="Normalize" width="90" x="112" y="300"/>
<operator activated="true" class="r:execute_script_r" compatibility="5.1.002" expanded="true" height="76" name="Execute Script (R)" width="90" x="313" y="255">
<parameter key="script" value="library(psych) library(igraph) dataout <- as.data.frame(9) x <- 5 y <- 23 z <- x * y print(search()) dataout <- z "/>
<enumeration key="inputs"/>
<list key="results">
<parameter key="dataout" value="Generic R Result"/>
</list>
</operator>
<connect from_op="Execute Script (R)" from_port="output 1" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
I show the following log messages. Note that the first Execute Script (R) line indicates that igraph and psych are loaded:Mar 20, 2011 4:07:45 PM INFO: Saved process definition at '//LocalRepository/TestR'.
Environment variables:
Mar 20, 2011 4:07:45 PM INFO: No filename given for result file, using stdout for logging results!
Mar 20, 2011 4:07:45 PM INFO: Loading initial data.
Mar 20, 2011 4:07:45 PM INFO: Process //LocalRepository/TestR starts
Mar 20, 2011 4:07:47 PM INFO: Execute Script (R): [1] ".GlobalEnv" "package:igraph" "package:psych"
Mar 20, 2011 4:07:47 PM INFO: Execute Script (R): [4] "package:JavaGD" "package:stats" "package:graphics"
Mar 20, 2011 4:07:47 PM INFO: Execute Script (R): [7] "package:grDevices" "package:utils" "package:datasets"
Mar 20, 2011 4:07:47 PM INFO: Execute Script (R): [10] "package:methods" "Autoloads" "package:base"
Mar 20, 2011 4:07:47 PM INFO: Saving results.
Mar 20, 2011 4:07:47 PM INFO: Process //LocalRepository/TestR finished successfully after 2 s
PATH contains \Program Files\R\R-2.12.2\bin\x64
R_HOME=D:\Program Files\R\R-2.12.2
JAVA_HOME=D:\Program Files\Java\jre6
RM setting rapidminer.r.native.lib = \Program Files\R\R-2.12.2\library\rJava\jri\x64\jri.dll
R Extension version is 5.1.002
Seems like something is different between our configurations, but I'm not sure what. What happens if you try typing in your script line by line into the interactive R Console view inside RM (i.e. not R standalone, but within RM). In particular, what happens when you type the library() statement? If it appears to work, what it returned when you type "search()" to see what packages are actually loaded?
Keith
0 -
Keith,
Thanks for taking time to check on your Win 7 setup. I really appreciate it.
From your comments and searching, it turns out my R user library is installed in C:\Users\........ and not in the C:\Programs folders.
After setting the R_LIBS_USER variable to the correct folder in c:\users the script runs now.
From this thread for R: Where does R look for library packages
http://www.mail-archive.com/r-help@r-project.org/msg124800.html
"...personal library directory, you need to set the environment variable R_LIBS_USER"
Sebastian,
Checking and setting the R_LIBS_USER is one more thing to suggest when someone can't get R working correctly with RM.
B.0 -
R will install libraries in an user directory if it has no writing access to the program directory, e.g. C:\Program Files\R\library
You can also change the R program directory access settings right after installation and before installing new libraries.0