Python and R

Alex Martelli aleaxit at yahoo.com
Thu Aug 31 17:01:39 EDT 2000


<dominic_barraclough at my-deja.com> wrote in message
news:8olo67$eso$1 at nnrp1.deja.com...
> Hi,
>
> I interested in doing some automated data analysis using R as the
> processer but driving the process with python. Has anybody attempted to
> do this?

I had a look today, because you raised my curiosity -- and it failed
for me just as well (and I think I know why).

> There is a com interface to R at the R site but I have be un able to
> get it to work with python - although it works with a test vb app.

I guess the 'vb test app' you're using is the one that comes with
the R COM adapter?  Not a good test case, see further.

> has any body been able to drive r with python via com

There is definitely a bug with the StatConnectorSrv COM adapter
for R.  Look at the following Visual Basic code (with Project
References including the StatConnector library):

Private Sub Command1_Click()
    Dim sc As StatConnector
    Set sc = CreateObject("StatConnectorSrv.StatConnector")
    Call sc.Init("R")
    Dim s As String
    s = sc.Evaluate("2+2")
    Text1 = "2+2 is " & s
End Sub

Private Sub Command2_Click()
    Dim sc As Object
    Set sc = CreateObject("StatConnectorSrv.StatConnector")
    Call sc.Init("R")
    Dim s As String
    s = sc.Evaluate("2+2")
    Text1 = "2+2 is " & s
End Sub

See the difference?  It's ONLY that, in Command1_Click, sc
is early-bound; in Command2_Click, it's late-bound.  Well,
Command1 works just fine; Command2 doesn't -- it gives
the error message "Type library is not registered"!

Working at it with a C++ coded client, it's even clearer that
the bug is in StatConnector...:
Type info available
Can't getTypeInfo... Com error (Library not registered.)
I.e., GetTypeInfoCount says it has a type-info, but
GetTypeInfo fails... because the type library is not
registered.

Haven't looked at the StatConnector sources, yet, but
I bet I know what's wrong -- confusion around type library
major/minor codes.  In the IDL, the version is given as
0.91; but in the registry, it's registered as "0.5b"; I bet
this has something to do with it.


I don't think Python can solve this, by itself, because it
doesn't do compile-time binding (except by modifying
the pythoncom C sources and recompiling it); it needs
to be able to do Automation binding, be it semi-early or
very-late ("dynamic").  So, the bugs needs to be fixed.


Are you in touch with the author of the COM adapter
for R?  If so, pls feel free to forward to him/her this
note.  Else, in the weekend, I may find time to look at
the sources and maybe fix them (no promises...:-).
But eventually the patch needs to be sent back to the
adapter author/maintained anyway, of course.


Alex






More information about the Python-list mailing list