#11266: Wrapper for R graphics commands.
---------------------------+------------------------------------------------
Reporter: JoalHeagney | Owner: was
Type: enhancement | Status: new
Priority: minor | Milestone: sage-4.7.1
Component: interfaces | Keywords: R, graphics, cairo, wrapper
Work_issues: | Upstream: N/A
Reviewer: | Author:
Merged: | Dependencies:
---------------------------+------------------------------------------------
Comment(by JoalHeagney):
Man, I haven't done ANY serious programming in python for ages.
Things I learnt: with keyword, apply depreciated, and how to use getattr.
I REALLY like jason's context handler. Simple and elegant. It shouldn't be
too difficult to extend it to do some checking of R capabilities and
perhaps capturing of the png.
Maybe what we really need is an extra page in the documentation that shows
all the R tricks people have found. I'm looking for a tutorial I saw some
time back which shows how to keep sage and R variables syncronised. Will
post it once I find it.
Anycase, the following achieves the same stuff as Jason's suggestion, but
as a class. It's missing a __repr__ method though. :(
{{{
#!python
class Rgraph:
def __init__(self,*args,**kwargs):
self.graph_args = args
self.graph_kwargs = kwargs
self.store = []
def savefunction(self,*args,**kwargs):
self.store.append((self.lastcall,args,kwargs))
def __getattr__(self,function):
self.lastcall = function
return self.savefunction
def show(self):
r.png(*self.graph_args,**self.graph_kwargs)
for function in self.store:
getattr(r,function[0])(*function[1],**function[2])
r.dev_off()
}}}
When called, it acts as follows:
{{{
gr.Rgraph()
gr.boxplot(someRdataIhadlyingaround)
show(gr)
}}}
It does have the advantage that the class can be called and "filled" in
one cell, and then displayed using show(gr). Then it can be "topped up"
with further r calls and the appended graph displayed using show(gr)
again.
Interestingly, this seems to swallow the extra info (PNG 2) that R throws
up for boxplot.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11266#comment:5>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.