datasets.mtcars fails on rpy2 2.3.0alpha1

Issue #102 resolved
kdd created an issue

Hello,

In my environment with rpy2 2.3.0alpha1, datasets.mtcars fails as follows:


$ python

Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)

[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

from rpy2.robjects.packages import importr

datasets = importr('datasets')

mtcars = datasets.mtcars

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

AttributeError: 'SignatureTranslatedPackage' object has no attribute 'mtcars'

import rpy2

rpy2.version

'2.3.0alpha1'

import rpy2.rinterface

rpy2.rinterface.R_VERSION_BUILD

('2', '15.1', '', '59600')

quit()

$ which python

/usr/bin/python

% sw_vers

ProductName: Mac OS X

ProductVersion: 10.7.5

BuildVersion: 11G63

$ which R

/usr/local/bin/R

$ R --version

R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"

Copyright (C) 2012 The R Foundation for Statistical Computing

ISBN 3-900051-07-0

Platform: x86_64-apple-darwin11.4.2 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.

You are welcome to redistribute it under the terms of the

GNU General Public License versions 2 or 3.

For more information about these matters see

http://www.gnu.org/licenses/.

$ R

R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"

Copyright (C) 2012 The R Foundation for Statistical Computing

ISBN 3-900051-07-0

Platform: x86_64-apple-darwin11.4.2 (64-bit)

:

:

:

str(mtcars)

'data.frame': 32 obs. of 11 variables:

$ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...

$ cyl : num 6 6 4 6 8 6 8 4 4 6 ...

$ disp: num 160 160 108 258 360 ...

$ hp : num 110 110 93 110 175 105 245 62 95 123 ...

$ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...

$ wt : num 2.62 2.88 2.32 3.21 3.44 ...

$ qsec: num 16.5 17 18.6 19.4 17 ...

$ vs : num 0 0 1 1 0 1 0 1 1 1 ...

$ am : num 1 1 1 0 0 0 0 0 0 0 ...

$ gear: num 4 4 4 3 3 3 3 4 4 4 ...

$ carb: num 4 4 1 1 2 1 4 2 2 4 ...

quit()

}}}

Comments (5)

  1. Laurent Gautier

    Good catch. I just plainly forget about that issue.

    There were changes in R, with the symbols identifying datasets in R packages are no longer listed in the R package's namespace.

    Stay tuned. This should be fixed soon.

  2. Laurent Gautier

    The earlier fix was in the documentation for graphics (but I forget to change that in other places in that same documentation):

    utils = importr('utils')
    tmp_env = Environment()
    utils.data('mtcars', envir = tmp_env)
    mtcars = tmp_env['mtcars']
    

    With 1746:6ee6a9a4a2ad, it can now also be done with:

    datasets = importr('datasets')
    mtcars = datasets.data.fetch('mtcars')['mtcars']
    

    Something simple would at the cost of potential obscure problems. For example:

    mtcars = datasets.data['mtcars']
    

    The issue with the above is that R's command 'data()':

    • does not return datasets but loads or creates them in the global environment

    • can load/create several objects

    • objects names do have to match the name of the dataset

  3. ghtmtt

    Hi,

    I'm also missing mtcars and have general problems with datasets. This is my configuration:

    import rpy2
    rpy2.__version__
    '2.9.4'
    

    and this all the problems I'm facing with the solutions of above:

    datasets = importr('datasets')
    mtcars = datasets.mtcars
    Traceback (most recent call last):
      File "/usr/lib/python3.6/code.py", line 91, in runcode
        exec(code, self.locals)
      File "<input>", line 1, in <module>
    AttributeError: module 'datasets' has no attribute 'mtcars'
    
    mtcars = datasets.data.fetch('mtcars')['mtcars']
    Traceback (most recent call last):
      File "/usr/lib/python3.6/code.py", line 91, in runcode
        exec(code, self.locals)
      File "<input>", line 1, in <module>
    AttributeError: module 'datasets' has no attribute 'data'
    
    mtcars = datasets.data['mtcars']
    Traceback (most recent call last):
      File "/usr/lib/python3.6/code.py", line 91, in runcode
        exec(code, self.locals)
      File "<input>", line 1, in <module>
    AttributeError: module 'datasets' has no attribute 'data'
    

    Any other solution?

    Thanks!

  4. Log in to comment