single integer number as "integer" or "numeric"

Issue #107 wontfix
kdd created an issue

Hello,

I found that the difference between rpy2 and R with regard to handling a single integer number as "integer" or "numeric" as follows:

% python
>>> import rpy2.robjects as ro
>>> r = ro.r
>>> print(r['class'](1))
[1] "integer"
% r
> x <- 1
> class(x)
[1] "numeric"

I also found that the R package "tableplot" (http://http://code.google.com/p/tableplot/) assumes the latter and checks the argument in the source code as follows:

  ## Check nBins
   if (class(nBins)[1]!="numeric") stop("<nBins> is not numeric")

Comments (1)

  1. Laurent Gautier

    Thanks for the report.

    In Python this is different:

    Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
    [GCC 4.7.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> type(1)
    <type 'int'>
    

    Same with the latest Python released:

    Python 3.3.0 (default, Oct  1 2012, 15:24:18) 
    [GCC 4.6.3] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> type(1)
    <class 'int'>
    

    rpy2 is providing access to R from Python. With that, the thinking is to expose R to a Python user/programmer (without assuming knowledge of R programming).

    I think that it makes sense to leave it the way it is, and should one want a float / R "numeric" it is only a matter of changing the code to "1.0" or "float(1)".

    Regarding the R package "tableplot", what you point out is a bug that should be reported to the package maintainer.

    I am marking this as "won't fix", but comments can continue if this is not believed to be a satisfactory conclusion.

  2. Log in to comment