Re: [Rd] Darwinian software development and the library function

2010-02-15 Thread Spencer Graves

Hi, Charlotte:


  I'm with Henrik:  I don't know the global consequences of print 
= function (...) base::print (...), but I wouldn't do it.



  Writing print.foo (x, ...) may violate your sense of 
aesthetics, but I avoid it.  I've done things like that in the past, 
then changed them to match the standard.  I've also gotten others to 
change their code or agree to let me change it to match the standard.  
As I previously mentioned, some of the code in my sos package violates 
a standard.  However, there were more substantive reasons than just 
aesthetics.



  I hope you'll entertain other analogies:  If red lipstick is 
required for something I want to support, I'll wear red lipstick, even 
if I think blue would go better with my outfit.  Shaving is a pain in 
the face, and I wore a flaming red beard for a quarter century until it 
finally came in white.  Then I started shaving to avoid projecting the 
image of a broken down old man;  people said I looked 25 years younger.  
(Younger than what?)  You can post a question to r-devel in Urdu or 
Farsi, but I doubt of many people will reply.



  Hope this helps.
  Spencer


On 2/13/2010 7:10 AM, Henrik Bengtsson wrote:

Hi.

Here are some guidelines that I find useful:

- Avoid changing the arguments of generic functions provided by the
default R packages, especially the ones in base.  Just, accept those
arguments.  If there are extra arguments you don't like, you can
always add '...' to your method and they will be accepted/pass the R
CMD check.

- Using an S3 generic function that only has '...' arguments seems to
work well and makes all methods for it pass R CMD check, regardless of
what arguments you use in your methods.

- Use R.methodS3 to define your methods, i.e. use setMethodS3(print,
foo, function(x, ...) { ... }).  This will check if there is a
generic function or not, and if missing, it will be created.
R.methodsS3 was created to make your S3 life easier.

My $.02

Henrik

On Sat, Feb 13, 2010 at 7:40 AM, Charlotte Maiamai...@gmail.com  wrote:
   

Hi Spencer,

Sorry, I wasn't very clear in my initial post.
The function print.foo (myfoo, ...) won't pass R check (unless one
overwrites print first).
One has to write print.foo (x, ...), which in my personal opinion, can
be problematic.

In my oosp package, I have overwritten print (along with a few others).
Initially, I overwrote both print and print.default.
However now, I merely use print = function (...) base::print (...).

Not really a generic, however it acts exactly the same (I think...).
Plus Rd documentation still documents print.mymethod in the usual way.


kind regards
Charlotte


On Sat, Feb 13, 2010 at 4:41 AM, spencergspencer.gra...@prodsyse.com  wrote:
 

Hi, Charlotte:

 I'm not sure what you mean.  If you mean writing something like
print.foo (myfoo, ...), this is relatively benign I suppose, but I avoid
it where feasible.  On multiple occasions, I've pushed collaborators and
even maintainers of other packages to change this or allow me to change it
to conform to the standard;  if my memory is correct, there have been
several violations of this standard in the fda package, which are no
longer there because I changed them.  If a user with an object x of class
foo writes print(x=x) or print(foo=x), I'm not sure what it would do, but
it might not be what you want.

 My sos package masks ?.  However, I don't like it.  I generally
consider such to be potentially user hostile, and whenever feasible, I
prefer to avoid such code.  I did it in this case for a couple of reasons.
  First, using ? (actually ???) seems so much easier to remember than
findFn that it justifies this transgression of standard protocol.  Second,
one of the leading figures in the R community (Duncan Murdoch) contributed
suggested we do this and contributed the code.

 If you change the definition of print itself, that seems to me to be a
much bigger issue, with consequences much more difficult to predict.  If
someone else also overwrites print making it different and incompatible
with yours, then your code may not work or theirs may not, depending on
which gets loaded first in the search path.  Worse, your code cannot
possibly have been tested as thoroughly as the standard code.  If your code
includes a subtle bug that only occurs under special circumstances, it may
be hard for the person experiencing the problem to find, because they don't
expect it.

 Hope this helps.
 Spencer


Charlotte Maia wrote:
   

Hi all,

Legend has it, that polite R programmers don't overwrite, say, the
print function.
However, this seems quite un-Darwinian to me (especially given that I
don't want to call all my arguments x and y).
I might want a function print.foo (myfoo, ...).

So I decided to be very impolite (in one of my packages) and overwrite
a few standard generics.
Plus, to the best of my knowledge it doesn't interfere with normal use
(yay...).

This brings us to the library 

[Rd] src/main/par.c (PR#14214)

2010-02-15 Thread A . R . Runnalls
At lines 1154-5 in par.c (at the latest svn revision 47460), in function
do_par():

if (new_spec  GRecording(call, dd))
GErecordGraphicOperation(op, originalArgs, dd);

if the call GErecordGraphicOperation gives rise to a garbage collection
(as it may), the return value of do_par will be trashed.

(Discovered during CXXR development.)

Andrew

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] org-mode (was Re: Feature Request: Multiline Comments)

2010-02-15 Thread Saptarshi Guha
Aah, yes I have read these. But my use is a bit different. I do not want R
output to be collected.  I wanted a nice IDE for R in emacs. So using
multiline comments and org-mode, i can have collapsible sections and
bookmarks in the source
.  I already use narrow-region to restrict views, but
its nice to open an R source file with a TOC, click on an entry and start
editing the function.

Thanks
saptarshi

On Mon, Feb 15, 2010 at 1:01 AM, Erik Iverson er...@ccbr.umn.edu wrote:
 Martin Morgan wrote:

 On 02/14/2010 08:11 AM, Saptarshi Guha wrote:


 Hello,
 Is it possible to extend the R lexer/parser to include multiline comments
 like
 /*
 acomment

 */
 ?
 This way I can integrate emacs org-mode with my R code, so that I can
 have a table of contents,
 section folding, html-output of source etc.


 Hi Saptarshi --

 Do you know about

  http://orgmode.org/worg/org-tutorials/org-R/org-R.php

 ?


 And also the very excellent org-babel, which can be used with R!

 http://orgmode.org/worg/org-contrib/babel/index.php


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] src/main/par.c (PR#14214)

2010-02-15 Thread Peter Dalgaard

a.r.runna...@kent.ac.uk wrote:

At lines 1154-5 in par.c (at the latest svn revision 47460), in function
do_par():

if (new_spec  GRecording(call, dd))
GErecordGraphicOperation(op, originalArgs, dd);

if the call GErecordGraphicOperation gives rise to a garbage collection
(as it may), the return value of do_par will be trashed.

(Discovered during CXXR development.)


Thanks. Committed to r-devel r51142.


--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel