I have installed the package “msImpute” (https://github.com/DavisLaboratory/msImpute), which is a package that is used for looking at protein data from mass spectrometry data and filling in missing values using statistics. It works fine within R, but I am having trouble importing and using it in Python. I have imported using the rpy2 package like so:
import rpy2.robjects as ro
from rpy2.robjects.packages import importr
from rpy2.robjects.vectors import StrVector
from rpy2.robjects import pandas2ri
from rpy2.robjects import r
pandas2ri.activate()
utils = importr('utils')
msImpute = importr('msImpute')
df_w = df.pivot(index='identifier',columns='sample', values='Intensity')
groups_vector = [groups_dict[col] for col in df_w.columns]
df_w_r = pandas2ri.py2rpy(df_w)
r_matrix = r('as.matrix')(df_w_r)
groups_vector_r = StrVector(groups_vector)
df_r_imp = msImpute.msImpute(r_matrix, method="v2-mnar", group=groups_vector_r)
Once I get to the last line, I always get the error: RRuntimeError: Fejl i (function (y, method = c("v2-mnar", "v2", "v1"), group = NULL, : Inf or NaN values encountered.
I am not sure why this is happening. I have checked my input and I can confirm there are no Inf values occurring. There are NaN values, but given that this is a package that is design to fill in NaN values, it makes no sense that this is a problem now.
The code in its native R script works fine with the same input. Could anyone tell me if this is a problem on my part with how I have imported the R package into python, or if some other issue is at hand?