How to call ltm function using rpy package in python

Piet van Oostrum piet at vanoostrum.org
Fri Jan 11 14:47:06 EST 2013


Mohit Khanna <mohit.personal1987 at gmail.com> writes:

> I am trying the following code--
>
> from rpy import *
> r.library("ltm")
>
> dat= #some data frame or matrix
> r.ltm(r('dat~z1'))
>
> error coming is---
> RPy_RException: Error in eval(expr, envir, enclos) : object 'dat' not found
>
> Please tell me the right way to call ltm function using rpy library

Your problem is that the 'dat' object is in the Python world but not in
the R world. However, the expression r('dat~z1') is looking for a 'dat'
object in the R world. So you must copy the Python object to the R
world.

I don't know if this will work in rpy, but it does work in rpy2. Rpy2
has much better possibilities than rpy. But just try it:

r['=']('dat', dat)
r.ltm(r('dat~z1'))
-- 
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]



More information about the Python-list mailing list