s-news
[Top] [All Lists]

Re: Calling newly compiled rpart

To: lsdst8+@pitt.edu
Subject: Re: Calling newly compiled rpart
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Tue, 8 Nov 2005 13:48:16 +0000 (GMT)
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <1082.24.3.122.82.1131340059.squirrel@webmail.pitt.edu>
References: <1082.24.3.122.82.1131340059.squirrel@webmail.pitt.edu>
You are diving into undocumented internal structures of rpart. But as a general principle, .C is not designed to pass S objects like a formula as here (except to pass them on to call_S). Your call is nothing like that to "s_to_rp" in rpart(), and I think it was fortuitous that you did not crash S-PLUS.

What do you actually want to do? Rpart is not just C code but also S code, and you need to use the latter to give you the correct calls.

On Mon, 7 Nov 2005 lsdst8+@pitt.edu wrote:

I need some guidance in calling a newly compiled version of rpart. I am
using rpart3 for windows and Microsoft Visual C+ 6.0. I have created a
project (to create a DLL) in Visual 6.0, added the rpart3 source code and
created a definition file that includes all of the function calls in
rpart3. Then, I compile (without making any changes) the code to create a
S.dll file. The DLL file is created without any errors.

In Splus 6.0, I load my dataset and dll
(dyn.open("C:/temp/rpart3/S.dll")). I try to call the newly compiled rpart
with the following statement:

               test1_.C("s_to_rp",
Surv(tlfup,sur)~(trt>1)+pnod+nucgr+mcsiz,x=T,y=T)

I get the following message:

           > test1
           Problem: Object "test1" not found, while calling subroutine 

           Use traceback() to see the call stack

Am I not making the proper function call? I thought that s_to_rp is the
function that I should call but I guess I am wrong. If I do the above
statement with rpart library loaded
(test1_rpart(Surv(tlfup,sur)~(trt>1)+pnod+nucgr+mcsiz,x=T,y=T)), it works.

To test the dll that I created, I added a simple function to rpart.c:
            void rsum(double* x, int* pn, double* mean, double* stdv)
                {
                    int n= *pn,i,j;
                    double sum=0, sqrsum=0;

                    for (i=0;i<n;i++)
                     {
                         sum += x[i];
                     }
                    *mean = sum/n;
                      for (j=0;j<n;j++)
                     {
                         sqrsum += ((x[j]- *mean)*(x[j]-*mean));
                       }
                    *stdv = sqrt(sqrsum/(n-1));
                   }
I compiled the code and created a new S.dll. I was able to get this
function to work with the following code in Splus:
           y_pnod
           z_0
           x_0
           x_.C("rsum",as.double(y),as.integer(402), as.double(x),
as.double(z))[[3]]

So the problem does not seem to be the DLL. Obviously, the problem is in
my call statement. Could anyone supply me with an example of how I could
call this newly compiled rpart? Sorry for the novice question but I have
not come across this information or I missed it. Any guidance would be
greatly appreciated. Thank you.


Scott Dean

--
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

<Prev in Thread] Current Thread [Next in Thread>