Reputation: 4540
This is a personal record, because the problem is difficult to Google, and I imagine I'll run into it again in a couple of years.
I have a script like:
library(FSelector)
table <- read.csv("somefile", header=0);
table <- table[,colSums(is.na(table))<nrow(table)]
imputed_table <- apply(table, 2, function(x){x <- replace(x, is.na(x), mean(x, na.rm=TRUE))});
nms <- colnames(table)
model <- information.gain(as.formula(paste(nms[length(nms)],"~.")), table)
When run with:
R --no-save < IG.R
this works fine, and prints the model.
When run with:
Rscript ./IG.R
this crashes with the error:
Error in .jarray(x) : could not find function "getClass"
Calls: information.gain ... read_model_frame_into_Weka -> read_data_into_Weka -> .jcall -> .jarray -> .Call
Execution halted
Why does this happen?
Upvotes: 0
Views: 1132
Reputation: 4540
This happens because Rscript does not load the rJava library by default, which is required by FSelector, but apparently is not loaded when FSelector is loaded. In contrast, the standard "R" command does load rJava by default.
To resolve this, add:
library(rJava)
to the script before the information.gain call.
Upvotes: 1