-------- Original-Nachricht --------
> Datum: Mon, 16 Feb 2009 15:19:57 +0000
> Von: Peter <rpy-l...@maubp.freeserve.co.uk>
> An: "RPy help,        support and design discussion list" 
> <rpy-list@lists.sourceforge.net>
> Betreff: Re: [Rpy] Using rpy in a python-com Object from Excel

> On Mon, Feb 16, 2009 at 2:20 PM, Fadhel benatig <fadhel.ben_a...@gmx.de>
> wrote:
> >
> > Hi all,
> >
> > I wrote a python-com program to be used within an Excel application.
> > This module uses the rpy functionalities! When I run the com-object
> > from a VBA function or procedure, I get the RuntimeError("Couldn't
> > execute the R interpreter R.exe") raised in the module rpy_tools.py.
> > After a simple debugging, I found that the problem lies in the function
> >
> > " def get_R_VERSION(RHOME=None, force_exec=False): "
> >
> > at line 64.
> 
> Have you tried just importing rpy at the python prompt (without using
> Excel)?  I suspect it will fail in the same way - but maybe via Excel
> the environment variables are different.
> 
> rpy (i.e. rpy1) first tries the RHOME environment variable.
> It then falls back on the registry (which requires extra modules to be
> installed)
> It then tries to run R directly, hoping it is on the path.
> 
> If you want to use this without changing the code try:
> * Defining the RHOME environment variable
> * Installing win32 http://starship.python.net/crew/mhammond/win32/ so
> the registry can be checked
> * Making sure R is on the PATH (another environment variable)
> 
> Peter

I'm using Rpy with python and I have no problems. The RHOME envir variable was 
setted and R.exe is on my Path. If I use the following RpyComInterface from 
Excel I get the Runtime Error.

Python Code:
from rpy_tools import *
import pythoncom
import time
import win32com.server.register

class RpyComInterface ( object ):
    _public_methods_ = ['TestRpyExcel']
    _reg_progid_ = 'RpyComInterface'
    _reg_clsid_ = '{7B8BF836-48C3-428A-BF2F-ABBAB938137D}'
    
    def TestRpyExcel(self):
        RHOME = get_R_HOME()
        print "======================="
        print "RHOME", RHOME
        rexec = os.path.join(RHOME, 'bin', 'R')
        stat, output = getstatusoutput('"%s" --version' % rexec )
        print "======================="
        print "stat", stat
        print "======================="
        print "output", output
        print "======================="
        rever = get_R_VERSION(RHOME)
        return [stat, output, rever ]
    
def register ():
    print "Testing Rpy For Excel..."
    print "Registering COM Server..."
    win32com.server.register.UseCommandLine( RpyComInterface )
    
if __name__ == '__main__' :
    register()

VBA Code:

Option Explicit
Function TestRpy() As Variant
    Dim objRpyComInterface As Object, result As Variant
    Set objRpyComInterface = CreateObject("RpyComInterface")
    result = objRpyComInterface.TestRpyExcel()
    Set objRpyComInterface = Nothing
    TestRpy = result
End Function


The Runtime Error is raised, because the stat variable has value 1 and the 
output string is empty.

Fadhel


-- 
Jetzt 1 Monat kostenlos! GMX FreeDSL - Telefonanschluss + DSL 
für nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to