title: Rpy2 on Linux. "R library contains no packages"-Error
body: <p>I tried installing rpy2 but it couldn't load any packages.</p>
  <p>My Linux is Mint 20,</p>
  <p>Python 3.8.2,</p>
  <p>R 3.6.3,<br />
  rpy2 3.3.5 (installed with pip, by the way)</p>
  <p>I remember I followed someone saying how to install R packages from within python and this is what I did:</p>
  <pre><code>import rpy2.robjects.packages as rpackages
  utils.chooseCRANmirror(ind=1)
  
  packnames= (&quot;ggplot2&quot;, &quot;hexbin&quot;)
  from rpy2.robjects.vectors import StrVector
  # R vector of strings (idk what it does)
  
  names_to_install= [x for x in packnames if not rpackages.isinstalled(x)] 
  if len(names_to_install) &gt; 0:
      utils.install_packages(StrVector(names_to_install))
  quit()
  
  # It will create a WARNING as such: 
  # R[write to console]:  'lib = &quot;/usr/local/lib/R/site-library&quot;' is not writable
  
  # Would you like to use a personal library instead? (yes/No/cancel) yes
  # Would you like to create a personal library
  # ‘~/R/x86_64-pc-linux-gnu-library/3.6’
  # to install packages into? (yes/No/cancel) yes
  
  # SO JUST SAY YES TWICE AND IT WILL CREATE A NEW FOLDER FOR YOUR INSTALLED PACKAGES!!
  </code></pre>
  <p>Well ok so my packages were installed in /R/x86_64-pc-linux-gnu-library/3.6</p>
  <p>But I've changed that later, when I tried some test code from the internet, I got a warning that I have no packages.</p>
  <pre><code>#!/usr/bin/python3.8
  
  import rpy2
  
  print(&quot;rpy2 version is:&quot;, rpy2.__version__)
  # &gt;&gt;rpy2 version is: 3.3.5
  
  import rpy2.robjects as robjects
  
                      # R PACKAGES
  # rpy2 is providing a function rpy2.robjects.packages.importr()
  # that makes that step very similar to importing Python packages.
  
  from rpy2.robjects.packages import importr  
  
  base = importr('base')
  utils = importr('utils')
  
  
  from rpy2.robjects import Formula, Environment
  from rpy2.robjects.vectors import IntVector, FloatVector
  from rpy2.robjects.lib import grid
  from rpy2.robjects.packages import data
  from rpy2.rinterface_lib.embedded import RRuntimeError
  import warnings
  
  # The R 'print' function
  rprint = robjects.globalenv.find(&quot;print&quot;)
  stats = importr('stats')
  grdevices = importr('grDevices')
  datasets = importr('datasets')
  
  grid.activate() 
  </code></pre>
  <p>The warning was:</p>
  <pre><code>R[write to console]: Warning messages:
  
  R[write to console]: 1: 
  R[write to console]: In (function (package, help, pos = 2, lib.loc = NULL, character.only = FALSE,  :
  R[write to console]: 
   
  R[write to console]:  library ‘/usr/lib/R/site-library’ contains no packages
  
  R[write to console]: 2: 
  R[write to console]: In (function (package, help, pos = 2, lib.loc = NULL, character.only = FALSE,  :
  R[write to console]: 
   
  R[write to console]:  library ‘/usr/lib/R/site-library’ contains no packages
  </code></pre>
  <p>then I tried to install the packages from R, so I sudo opened R and typed
  <code>install.packages()</code>
  for some packages like base, utils, grDevices..., which count as base packages, it said it doesn't update it for that reason. But I found out their path is &quot;/usr/lib/R/library&quot;</p>
  <p>then for other packages I wanted to install, like ggplot2, it installed it into &quot;/usr/local/lib/R/site-library&quot;, which is what was wanted in the first installing step.</p>
  <p>neither of those are what rpy2 wanted. It wanted /usr/lib/R/site-library</p>
  <p>But I even found out I can add a path when importing a package like this:</p>
  <pre><code>base = importr('base', lib_loc=&quot;/usr/lib/R/library&quot;)
  </code></pre>
  <p>it worked kind of.
  I've tested my code from above (second box) line by line and I've added it for all packages imported with importr.
  And most of the <code>from x import y</code> worked aswell. Just not grid.
  <code>from rpy2.robjects.lib import grid</code>
  still gave me the same &quot;library ‘/usr/lib/R/site-library’ contains no packages&quot; message.
  But I don't know how to add a path there!!</p>
  <p>My Prof and I tried to find a solution for 2 days now. I am really desperate.
  Why are the paths even such an issue? I saw noone talking about that the default paths it chooses are not correct, and everything I found was just for windows! If the defaults are not correct, shouldn't that be in the documentation? And if it just works for everyone else, what have I done wrong?</p>
  <p><a href="https://stackoverflow.com/questions/49108205/r-library-contains-no-packages">R library contains no packages</a>
  was a similar question, but his rpy2 wanted to use usr/local/lib, which would be correct in my case!! (and there was not really an answer, at least nothing that I understood)</p>