ralhei / pyRserve

A python client for Rserve (network layer to remote R server)
Other
48 stars 13 forks source link

Parser error when using dbConnect #8

Closed nsh87 closed 9 years ago

nsh87 commented 9 years ago

Thanks for this very useful package, first of all. I can only assume this is a parser error based on the traceback, if it is not sorry.

[127.0.0.1:2200] out: >>> c.eval("packageVersion('RSQLite')")
[127.0.0.1:2200] out: [array([1, 0, 0], dtype=int32)]
# Connect to a DB, or create it in the wd() if it doesn't exist
[127.0.0.1:2200] out: >>> c.eval("con <- dbConnect(RSQLite::SQLite(), dbname='testdb')")
[127.0.0.1:2200] out: Traceback (most recent call last):
[127.0.0.1:2200] out:   File "<console>", line 1, in <module>
[127.0.0.1:2200] out:   File "/server/env.example.com/local/lib/python2.7/site-packages/pyRserve/rconn.py", line 76, in decoCheckIfClosed
[127.0.0.1:2200] out:     return func(self, *args, **kw)
[127.0.0.1:2200] out:   File "/server/env.example.com/local/lib/python2.7/site-packages/pyRserve/rconn.py", line 159, in eval
[127.0.0.1:2200] out:     message = rparse(src, atomicArray=atomicArray)
[127.0.0.1:2200] out:   File "/server/env.example.com/local/lib/python2.7/site-packages/pyRserve/rparser.py", line 606, in rparse
[127.0.0.1:2200] out:     return rparser.parse()
[127.0.0.1:2200] out:   File "/server/env.example.com/local/lib/python2.7/site-packages/pyRserve/rparser.py", line 414, in parse
[127.0.0.1:2200] out:     message = self._parse()
[127.0.0.1:2200] out:   File "/server/env.example.com/local/lib/python2.7/site-packages/pyRserve/rparser.py", line 441, in _parse
[127.0.0.1:2200] out:     expression = self._parseExpr()
[127.0.0.1:2200] out:   File "/server/env.example.com/local/lib/python2.7/site-packages/pyRserve/rparser.py", line 448, in _parseExpr
[127.0.0.1:2200] out:     lexeme = self.lexer.nextExprHdr()
[127.0.0.1:2200] out:   File "/server/env.example.com/local/lib/python2.7/site-packages/pyRserve/rparser.py", line 265, in nextExprHdr
[127.0.0.1:2200] out:     (hex(rTypeCode), startLexpos, length))
[127.0.0.1:2200] out: RParserError: Unknown SEXP type 0x7 found at lexpos 20, length 180
# The connection and the DB is made, despite the warnings
[127.0.0.1:2200] out: >>> c.eval('class(con)')
[127.0.0.1:2200] out: AttrArray(['SQLiteConnection'],
[127.0.0.1:2200] out:       dtype='|S16', attr={'package': array(['RSQLite'],
[127.0.0.1:2200] out:       dtype='|S7')})

Just for reference, the same thing in R would be:

> con <- dbConnect(RSQLite::SQLite(), dbname='testdb')
> con
<SQLiteConnection>
> class(con)
[1] "SQLiteConnection"
attr(,"package")
[1] "RSQLite"

I could imagine a parser error on <SQLiteConnection>, but note that there is no output from the command generating the error, con <- dbConnect(RSQLite::SQLite(), dbname='testdb').

ralhei commented 9 years ago

Thanks for the report. Indeed I had never come across db connection objects in R so far, so that's probably why there is this implementation issue. Hope I can fix this by the end of this week.

ralhei commented 9 years ago

Hi Nikhil, I've uploaded a new version (0.8.2) to pypi, this should fix your problem.

nsh87 commented 9 years ago

Works perfectly now. I like the output showing the dbname of the connection. Thanks! My output is a bit wonky because I'm operating over Fabric, but essentially:

[127.0.0.1:2200] out: >>> con.eval("c <- dbConnect(RSQLite::SQLite(), dbname='testdb')")
[127.0.0.1:2200] out: <S4 attrs=[('Id', 22), ('dbname', array(['testdb'],
[127.0.0.1:2200] out: dtype='|S59')), ('loadable.extensions', array([ True], dtype=bool)), ('flags', array([6], dtype=int32)), ('vfs', array([''],
[127.0.0.1:2200] out: dtype='|S1')), ('class', AttrArray(['SQLiteConnection'],
[127.0.0.1:2200] out: dtype='|S16', attr={'package': array(['RSQLite'],
[127.0.0.1:2200] out: dtype='|S7')}))]>