After some trouble I successfully installed rpy2.
My aim is to build models (gam; library mgcv of Simon Wood) and use the predict function by passing a pandas dataframe from python through rpy2 to a gam model and retrieve the prediction.
The R script is tested by loading the txt file and process it through the same R functions as are called by the python/rpy2 script and it works fine. In the python script I start from the pickled version of the text file (as if I am in my final code, starting from a pandas dataframe).
I am also capable of triggering other errors in the R script that do make sense (passing a empty dataframe, or a dataframe with a column missing to successfully perform a prediction both trigger an error as it would in R.) I do actually get into the gam function with the input data intact.
I am close to the finish, but i keep getting this error:
Error in ExtractData(object, data, NULL) : 'names' attribute [1] must be the same length as the vector [0]
I don't know any way to get more feedback from R in my python script. How can I debug? Or can anybody point me out what might the problem in R? Or is this a part of the ".convert_to_r_dataframe()" function I do not grasp completely???
R-code:
f_clean_data <- function(df) {
t = df
... some preprocessing
t
}
tc <- f_clean_data(t)
f_py_gam_predict <- function(gam, df) {
dfc = f_clean_data(df)
result <- predict(gam, dfc)
result
}
bc_gam = gam(BC ~
+s()
.... some gam model
, data=tc, method="REML"
)
summary(bc_gam)
testfile = 'a_test_file.txt'
ttest <- read.table(file=testfile ,sep='\t',header=TRUE);
result = f_py_gam_predict(bc_gam, ttest)
The f_py_gam_predict is available in the python script.
Thanks, Luc