#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):

 It's been a while since I programmed python, and I'm still learning some
 of the new features.

 I was under the assumption that to use `__getattr__` for dynamic methods,
 a function had to be returned, which was then called with arguments? This
 is why I have the `__getattr__` store the function name in self.lastcall,
 so it could be passed to savefunction.

 I'm well aware that my code will need a lot of work to streamline it, but
 I thought getting a basic structure up might help the more advanced
 coders.

 I'll have a look to see what needs to be done to add tab completions.

 What I'm really focusing on now is image caching. From what I understand R
 graphics get output via the following process:

 Sage notebook scans through the directory created by the cell, looking for
 any images that have been created. It then drops a html link referring to
 the image into the notebook output cell.

 This suggests a method of caching image results as an optimisation to
 speed up multiple calls.

 1. The show method checks to see if a self.cache variable is defined.

 2a. If it isn't, the show method runs all the stored r graphics calls, and
 stores the name and cell directory location of the png file in the
 self.cache variable.

 2b. If the self.cache variable IS defined, show( ) COPIES the png file
 from the old cell directory into the new cell directory, and relies on
 sage notebook to take care of the loading.

 3. `__getattr__` has an extra line added that deletes self.cache every
 time a new r graphic method is called.

 This SHOULD result in the Rgraphic object copying the old png into the new
 cell, as long as no new method calls have been added to the Rgraphic.

 After that, if we go for my class method over your neat "with" method, we
 just need to come up with a nice way to control the list of r graphic
 calls - i.e. some append/delete methods.

 Is there a way to add your "with" algorithm so that it's automatically and
 invisibly called from the sage notebook on any r function that requires
 graphics (maybe a decorator or something applied to the R. class)?

 Because then we could strip out all the graphical stuff from my class,
 rename it Rcommandlist or something, and just have a session like this:

 {{{
 #!python
 all_the_with_stuff_done_invisibly_by_sage(including, checking, image,
 capabilities)

 class Rcommandlist:
     def __init__(self):
         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):
         for function in self.store:
             getattr(r,function[0])(*function[1],**function[2])

 gr = Rcommandlist()
 gr.boxplot(arguments)
 gr.lowlevelRgraphicfunctions()
 show(gr)
 }}}

 Because I look at my Rgraphic class method, and based on lines saved, the
 only advantage it has over traditional r invocation, is that it allows the
 r commands to be stored in an object. I'd much prefer invisible graphic
 calls, even if this loses the possibility of image caching (Because
 frankly, how often does somebody create an identical graph __twice__ in
 the same spreadsheet?).

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11266#comment:8>
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.

Reply via email to