title: Calling functions from within R packages in Python using importr
body: <p>I am using a feature selection algorithm called mRMRe in R , but I need to call it from Python. I have successfully installed the package and being able to call it from Python. I need to access some functions within the R mRMRe package like mRMR.data to convert the dataframe into a format as needed by the algo.</p>
  
  <pre><code>from rpy2.robjects.packages import importr
  utils = importr('utils') #-- Only once.
  utils.install_packages('mRMRe')
  
  # Now we begin by loading in the R packages
  pymRMR = importr('mRMRe')
  
  pymRMR
  Out[53]: rpy2.robjects.packages.Package as a &lt;module 'mRMRe'&gt;
  </code></pre>
  
  <p>However when I try to call it's function mRMR.data I get an error:</p>
  
  <pre><code>AttributeError: module 'mRMRe' has no attribute 'mRMR'
  </code></pre>
  
  <p>same is the case if I try to do with a different library:</p>
  
  <pre><code>datasets = importr('datasets')
  datasets.data.fetch('mtcars')
  Traceback (most recent call last):
  
    File "&lt;ipython-input-56-b036c6da58e1&gt;", line 2, in &lt;module&gt;
      datasets.data.fetch('mtcars')
  
  AttributeError: module 'datasets' has no attribute 'data'
  </code></pre>
  
  <p>I got this datasets part from <a href="https://sites.google.com/site/aslugsguidetopython/data-analysis/pandas/calling-r-from-python" rel="nofollow noreferrer">enter link description here</a></p>
  
  <p>I am not sure what I am doing wrong. I earlier had imported as used R's medcouple function from mrfDepth as below:</p>
  
  <pre><code>import rpy2.robjects as ro
  #now import the importr() method
  from rpy2.robjects.packages import importr
  utils = importr('utils') #-- Only once.
  utils.install_packages('mrfDepth')
  # Now we begin by loading in the R packages
  mrfdepth = importr('mrfDepth')
  mc = mrfdepth.medcouple(yr)[0]
  return mc
  </code></pre>
  
  <p>Can someone please help me to resolve this?</p>