greenplum-db / PivotalR-archive

An convenient R tool for manipulating tables in PostgreSQL type databases and a wrapper of Apache MADlib.
https://pivotalsoftware.github.io/gp-r/
125 stars 53 forks source link

Namespace for cbind not set correctly #54

Open iyerr3 opened 7 years ago

iyerr3 commented 7 years ago

Bug report from Mark Malamut:

I believe I encountered what appears to be a small bug in this package that I cannot get around when trying to incorporate it into my own package which provides a db access layer for our team. Here is what I believe is the problem.

Note that I am using the most recent version from CRAN 0.1.18.3

The PivotalR package implements cbind and therefore overrides the base cbind when the fully library is loaded using the library(PivotalR) directive. From the behavior I have seen it appears that a reference to cbind in your package uses whatever cbind is available in the current environment as opposed to explicitly using PivotalR::cbind. I believe this to be the case as my code works fine when specifying library(PivotalR) but fails during db.disconnect with the following when the library is not fully loaded.

Sample Code

#library(PivotalR)

connect = function(){
  PivotalR::db.connect(host='x1', user='x2', password='x3', dbname='x4', quick=TRUE)
}

disconnect = function(id){
  PivotalR::db.disconnect(conn.id=id, verbose=TRUE)
}

query = function(str){
  id = connect()
  result = PivotalR::db.q(str, conn.id=id, verbose=TRUE, nrows='all')
  disconnect(id)

  result
}

X = query(“SELECT * FROM <table>”)
Error in .localVars$conn.type[[conn.pkg]] <- .localVars$conn.type[[conn.pkg]][-which(.localVars$conn.type[[conn.pkg]] == : replacement has length zero

When the library PivotalR is loaded, I see the following informational messages and my code works without error:
> library("PivotalR", lib.loc="~/R/win-library/3.3")

Attaching package: ‘PivotalR’

The following objects are masked from ‘package:stats’:

    sd, var

The following object is masked from ‘package:base’:

    cbind

Which is why I believe there is an implicit call to cbind in your code ( It doesn’t seem that sd or var are the issue). Note that the first time it fails in db.disconnect but if you rerun without resetting the environment subsequent calls will fail in db.connect with the following error message:

Error in .localVars$conn.type[["rpostgresql"]] <- c(.localVars$conn.type[["rpostgresql"]], : more elements supplied than there are to replace