> >> What seems ideal to me would be a way to grab the R console output one
> >> line at a time rather than all at once so I can just append those lines
> >> individually to my gtk text buffer. I can easily do this for a specific
> >> task, such as only for a data.frame, programmatically break it apart by
> >> rows. However, I'm hoping for something more general that could apply to
> >> any output.
> 
> Erh... did you check the example ?
> http://bitbucket.org/lgautier/rpy2/src/813a7bc798ae/demos/radmin.py
> It seems to be doing what you are looking for.
> 

Yes, checked it before I sent the email (ah, but if only I found it
before I started coding...I wouldn't have reinvented the wheel so much;
though I guess it was better to learn on my own.). My code for adding
the result to the gtk.TextBuffer is essentially the same. 

What I meant was having access to the lines of output in R before it's
converted to a Python string....but see below for a workaround.

> >> I have tried to set robjects.rinterface.setWriteConsole(f) to some
> >> function f that just appends to a buffer, but that console callback
> >> function doesn't seem to append anything to the buffer if I do a call to
> >> robjects.r("some command here").
>  >
> > robjects.r("foo") doesn't print anything itself. (Unless 'foo' calls
> > the print() function.) Try robjects.r("print(foo)") or
> > robjects.r["print"](robjects.r("foo")).
> 
> The confusion might occur because genuine R console calls print on an 
> object (a bit like a Python console calls the method __repr__() ).

I'm embarassed, because I read about using R's print() function in a
former email on this email list...but somehow I didn't connect the dots
for my own problem. Anyway, I'm happy to see that when I do it correctly
and the print() command's output is appended to the buffer, the output
is separated into many cells rather than as one big string.

I just whipped up a quick function to combine cells into lines:
    def buf2linebuf(buf):
        line = ""
        line_buf = []
        for cell in buf:
            if cell[0] == '\n':
                line_buf.append(line)
                line = cell.lstrip()
            else:
                line = line + cell
        return line_buf

When I then appended each of these lines one at a time to my TextBuffer,
the output was no longer truncated. 

Thanks for your quick help. Once I get a bit more comfortable in Python,
I'll be happy to help out with RPy since my project will be relying so
heavily on it.

cheers,
brandon


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to