X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 03 May 2012 06:35 PM by  anon
Call R function from IDL?
 6 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
03 May 2012 06:35 PM
    Hi guys: R is a free software environment for statistical computing. Is there any way to call R function from IDL. Very thanks!! dave

    Deleted User



    New Member


    Posts:
    New Member


    --
    04 May 2012 08:57 AM
    I don't know of a way to interface directly, however, IDL has several ways to integrate external code. At minimum you could use SPAWN to fire up another executable to perform some operation. I'm not that familiar with R, but if there is a way to call R from C/C++, then you could write a C/C++ DLM module, which would be called from IDL, and the DLM would perform the interface with R. Check out the docs in C:\Program Files\Exelis\IDL82\help\pdf, specifically "edg.pdf" and "bridges.pdf" for ways to interface with external CODE. R is a statistical computing package if I remember correctly. If all you need are a set of statistical functions, I would instead suggest (rather than attempt to interface IDL with R), that you check out the IDL Help section: Routines by Topic/Mathematics There you will find that IDL has a large set of tools for math/statistics already available. I would be surprised if IDL didn't have what you need in that regard. What types of calculations do you need to perform? -Josh Exelis VIS

    Deleted User



    New Member


    Posts:
    New Member


    --
    13 May 2012 06:30 AM
    Hi, josh: I want to use the weather verifcation packages from R. I find the statconnDCOM (http://www.statconn.com/products.html), which can provide COM object to communicate with R. But, the 'StatConnector' COM object has 'init' method, which can not be called by IDL's IDLcomIDispatch ojbect. So, how can I make this? Very thanks! Dave

    Deleted User



    New Member


    Posts:
    New Member


    --
    16 May 2012 08:54 AM
    Ah, ok. So the problem here is that IDL reserves "init" for object creation, and so it won't be possible to call that method directly. However, it may work (I haven't tested this) to use CALL_METHOD instead, which may allow it to work. Try the following (taken from the IDL help). Result = CALL_METHOD(Name, ObjRef, [, P1, ..., Pn]) or CALL_METHOD, Name, ObjRef, [, P1, ..., Pn] Where "Name" is the method, in this case "init", and "ObjRef" is your COM object, "Pn" are any optional parameters that the object may accept. Give that a try, I'm not sure that that will work though, I haven't tested that. -Josh Exelis VIS

    Deleted User



    New Member


    Posts:
    New Member


    --
    16 May 2012 06:58 PM
    Hi josh: It's not work. IDL> ObjRef = OBJ_NEW('IDLcomIDispatch$PROGID$StatConnectorSrv.StatConnector.1') IDL> call_method, 'init', objref, 'R' % Lifecycle methods cannot be called in this context. % Execution halted at: $MAIN$ Dave

    Deleted User



    New Member


    Posts:
    New Member


    --
    16 May 2012 08:00 PM
    Hi josh: I find the solution. 'init' method can only be called in class 'init' function. So I construct the fellowing class: FUNCTION nmc_com_bridge_r::get_obj return, self.objRef END PRO nmc_com_bridge_r::cleanup obj_destroy, self.objRef END FUNCTION nmc_com_bridge_r::init self.objRef = OBJ_NEW('IDLcomIDispatch$PROGID$StatConnectorSrv.StatConnector.1') call_method, 'init', self.objRef, 'R' return, 1 END PRO nmc_com_bridge_r__define COMPILE_OPT idl2, hidden objref = {nmc_com_bridge_r, $ objRef:obj_new()} END obj = obj_new('nmc_com_bridge_r') R = obj->get_obj() R->setSymbol, 'a', indgen(10) R->EvaluateNoReturn, 'plot(a)' obj_destroy, obj END

    Deleted User



    New Member


    Posts:
    New Member


    --
    18 May 2012 09:03 AM
    Excellent, I'm glad that worked for you. Post back if you run into any problems. -Josh Exelis VIS
    You are not authorized to post a reply.