title: how to use rpy2 within a packrat environment?
body: <p>I try to use an R package that I have installed using the R package 'packrat' that allow to create a virtual environment similar to virtuanlenv in python. But I do not succeed.</p>
  
  <p>Within a console using R I can run successfully the following code:</p>
  
  <pre><code>cd /path/to/packrat/environment
  R # this launch a R console in the packrat environment
  library(mycustompackage)
  result = mycustompackage::myfunc()
  q()
  </code></pre>
  
  <p>I would like to do the same using rpy2, but I'm unable to activate the packrat environment. Here follow what I've tested unsuccessfully.</p>
  
  <pre><code>from rpy2.robjects import r
  from rpy2.robjects.packages import importr
  
  packrat_dir = r.setwd('/path/to/packrat/environment')
  importr('mycustompackage')
  result = r.mycustompackage.myfunc()
  </code></pre>
  
  <p>But it fails at 'importr' because it cannot find the package 'mycustompackage'. Either unsuccessfull :</p>
  
  <pre><code>importr('mycustompackage', lib_loc='/path/to/packrat/environment')
  </code></pre>
  
  <p>Neither: </p>
  
  <pre><code>os.environ['R_HOME'] = '/path/to/packrat/environment'
  importr('mycustompackage', lib_loc ='/path/to/packrat/environment')  
  </code></pre>
  
  <p>Any suggestion on how to use rpy2 with packrat environments?</p>