Error in loadNamespace(name) : there is no package called ‘ggplot2’

Issue #137 resolved
Kamil Slowikowski created an issue

Hi,

I want to use ggplot2 with python but I encounter the error

Error in loadNamespace(name) : there is no package called ‘ggplot2’

as shown below.

I have ggplot2 installed so I don't know how to proceed from here.

What should I check next?


lsb_release -d
Description:    Ubuntu 12.04.2 LTS


python --version
Python 2.7.3


python -m 'rpy2.tests'
rpy2 version: 2.3.6
built against R version: 3-0.1--62743
Error in loadNamespace(name) : there is no package called ‘ggplot2’
.................................................................................................................................................................................................................................................................................................E........................................................
======================================================================
ERROR: testPandas2ri (rpy2.robjects.tests.testPandasConversions.PandasConversionsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/rpy2/robjects/tests/testPandasConversions.py", line 74, in testPandas2ri
    pandas_df = robjects.conversion.ri2py(rdataf)
  File "/usr/local/lib/python2.7/dist-packages/rpy2/robjects/pandas2ri.py", line 63, in ri2pandas
    raise NotImplementedError("Conversion from rpy2 DataFrame to pandas' DataFrame")
NotImplementedError: Conversion from rpy2 DataFrame to pandas' DataFrame

----------------------------------------------------------------------
Ran 346 tests in 3.681s

FAILED (errors=1)
> loadNamespace('ggplot2')
<environment: namespace:ggplot2>


> loadNamespace('ggplot3')
Error in loadNamespace("ggplot3") : there is no package called ‘ggplot3’


> install.packages("ggplot2")
Installing package into ‘/home/kamil/Dropbox/lib/R/x86_64-pc-linux-gnu-library(as ‘lib’ is unspecified)
trying URL 'http://cran.mtu.edu/src/contrib/ggplot2_0.9.3.1.tar.gz'
Content type 'application/x-gzip' length 2330942 bytes (2.2 Mb)
opened URL
==================================================
downloaded 2.2 Mb

* installing *source* package ‘ggplot2’ ...
** package ‘ggplot2’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (ggplot2)

The downloaded source packages are in/tmp/RtmpSTIj5E/downloaded_packages’


> version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          3                           
minor          0.1                         
year           2013                        
month          05                          
day            16                          
svn rev        62743                       
language       R                           
version.string R version 3.0.1 (2013-05-16)
nickname       Good Sport                  

Comments (7)

  1. Laurent Gautier

    hmm... this might be because you have R_LIBS set and rpy2 is starting R in --vanilla mode by default. May be not the most clever thing to do (the default to -- vanilla, not the use of R_LIBS), and may be I should change the default.

    Check the documentation about initializing the embedded R

  2. Kamil Slowikowski reporter

    Laurent, thank you! I didn't know where to look and I missed that part of your documentation when I was browsing through it. I'm very glad you replied.

    Indeed, I have R_LIBS_USER set in my ~/.Renviron file, and it is ignored by --vanilla:

      --vanilla     Combine --no-save, --no-restore, --no-site-file,
                    --no-init-file and --no-environ
    

    The solution is to do as you say and initialize the embedded R without the --no-environ option:

    import rpy2.rinterface
    rpy2.rinterface.set_initoptions(('rpy2', '--no-save', '--no-restore', '--quiet'))
    from rpy2.robjects.lib import ggplot2
    

    My opinion is that the default should respect my R_LIBS_USER variable. This makes life more predictable because R packages installed in my local home directory are unsurprisingly available through rpy2 without any extra commands.

  3. Kamil Slowikowski reporter

    By default, rpy2 initializes R with --vanilla and so it ignores the environment variable R_LIBS_USER. This is a workaround:

    import rpy2.rinterface
    rpy2.rinterface.set_initoptions(('rpy2', '--no-save', '--no-restore', '--quiet'))
    from rpy2.robjects.lib import ggplot2
    
  4. Mo Koneshloo

    ValueError: All options should be bytes.

    rpy2.rinterface.set_initoptions(('rpy2', '--no-save', '--no-restore', '--quiet'))
    
    ValueError: All options should be bytes.
    
  5. Log in to comment