[R] using RSperl with "tree" package

Duncan Temple Lang duncan at wald.ucdavis.edu
Mon Nov 12 00:51:52 CET 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Rachana Jain wrote:
> Hello,
> 
> I am trying to use the "tree" package in R with RSperl.
> 
> I have generated a regression tree using the "tree" package in R and saved it in a file say "RegTree_2.Rdata"
> 
> If I use the predict function from R command line, it works fine. However, I want to use it from within perl using RSperl. To do that, here is what I do,
> 
> my $regTree = "RegTree_2.Rdata";
> my $tree = &R::load($regTree);
> my $ans = &R::call("predict.tree", $tree, $_[0]);
> 
> On running my code, I get the following error:  
> Error in predict.tree("rtree_2", list("5031601", "GS0098", 0, "1", "1",  : 
>         not legitimate tree
> 

One of the things that comes to mind immediately is that the return
value of the R function load is a character vector giving the names of
the variables that were assigned during the restoration of the objects
from the file.  Thus, the value of $tree in Perl will be a simple
string (or an array of strings).

The call to predict.tree bypasses the generic predict method.
So if you called predict.tree() with a string rather than a tree
you will see the "not legitimate tree" error.

Why you see list("5031601",...)  is not clear to me unless
that is currently what is in $tree and so you saved not just
the tree but a lot more besides.

Also, predict will want a data frame as the second argument.
How does $_[0] expand to such an R object when passed from Perl
to the R function?

 D.

> Any help would be appreciated.
> 
> Thanks
> -Rachana
> 
> 
>     Rachana Jain
>   rachanaj at yahoo.com
>   Ph: 408-499-9802 (Cell)
>         513-556-7509 (Res.)
>   2931 Scioto Lane Apt. No. 1002
>   Cincinnati OH - 45219, U.S.A.
> 
> 
> 
>  __________________________________________________
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHN5WY9p/Jzwa2QP4RAtCMAJ9sdT+9JKNLNrZvY2L2W4aaovWXfQCfe7Ya
+CePYpM4MG1VxRSziKRziO0=
=FWyr
-----END PGP SIGNATURE-----



More information about the R-help mailing list