File: erobj.py

package info (click to toggle)
rpy 1.0.3-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 636 kB
  • ctags: 774
  • sloc: ansic: 2,139; python: 1,591; makefile: 119; sh: 73
file content (27 lines) | stat: -rw-r--r-- 674 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from rpy import *

class ERobj:

    def __init__(self, robj):
        self.robj = robj

    def as_r(self):
        return self.robj

    def __str__(self):
        a = with_mode(NO_CONVERSION,
                      lambda: r.textConnection('tmpobj', 'w'))()
        r.sink(file=a, type='output')
        r.print_(self.robj)
        r.sink()
        r.close_connection(a)
        str = with_mode(BASIC_CONVERSION,
			lambda: r('tmpobj'))()
	return '\n'.join(as_list(str))

    def __getattr__(self, attr):
        e = with_mode(BASIC_CONVERSION,
                      lambda: r['$'](self.robj, attr))()
        if e:
            return e
        return self.__dict__[attr]