Re: [R] round() and negative digits

2011-10-11 Thread Rolf Turner

On 11/10/11 08:17, Michael Friendly wrote:

On 10/9/2011 6:18 AM, Prof Brian Ripley wrote:


Sometimes it is better not to document things than try to give precise
details which may get changed *and* there will be useRs who misread (and
maybe even file bug reports on their misreadings). The source is the
ultimate documentation.


I can't agree with this less.  The source does the computation. The 
documentation says how to use it and what it should do.  Corner cases

can be trapped in code or mentioned in Notes.  But the source is
only useful if you can easily find it and then can understand what it is
doing, particularly for a .Primitive like round().
The source is only the documentation of last resort.


I agree.  It seems to me that saying that the source is the ultimate 
documentation

is rather like (in pure mathematics) saying that all maths follows from the
Zermello-Fraenkel axioms plus the Axiom of Choice, so those axioms are 
all that we

need to tell anyone.

cheers,

Rolf Turner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-11 Thread Duncan Murdoch

On 11-10-11 7:14 PM, Rolf Turner wrote:

On 11/10/11 08:17, Michael Friendly wrote:

On 10/9/2011 6:18 AM, Prof Brian Ripley wrote:


Sometimes it is better not to document things than try to give precise
details which may get changed *and* there will be useRs who misread (and
maybe even file bug reports on their misreadings). The source is the
ultimate documentation.


I can't agree with this less.  The source does the computation. The
documentation says how to use it and what it should do.  Corner cases
can be trapped in code or mentioned in Notes.  But the source is
only useful if you can easily find it and then can understand what it is
doing, particularly for a .Primitive like round().
The source is only the documentation of last resort.


I agree.  It seems to me that saying that the source is the ultimate
documentation
is rather like (in pure mathematics) saying that all maths follows from the
Zermello-Fraenkel axioms plus the Axiom of Choice, so those axioms are
all that we
need to tell anyone.


R is an open source project.  That means we expect people to look at the 
source, to answer some of their own questions, to suggest improvements, 
to point out errors.  If you don't look at it, you aren't holding up 
your side of the bargain.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-11 Thread Jeff Newmiller
The source does not document intent. I, too disagree with Dr Ripley on this 
point. The library mechanism insists that some attempt at documentation be 
included with the source, for good reason.

I would rather the documentation assert intent to support negative rounding 
values and later add the caveat that it may not be achievable in all cases than 
not mention the option at all.

It is much easier to critique the code and documentation together than depend 
purely on the algorithmic expressions in the code... I may wonder if the author 
intended the code to have some odd corner case behavior in order to meet a 
performance goal. Documentation that addresses that helps, and documentation 
that doesn't may simply be mysterious. Documentation that disagrees with the 
code prompts repairs... of the code, or the documentation.
---
Jeff Newmiller The . . Go Live...
DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Duncan Murdoch murdoch.dun...@gmail.com wrote:

On 11-10-11 7:14 PM, Rolf Turner wrote:
 On 11/10/11 08:17, Michael Friendly wrote:
 On 10/9/2011 6:18 AM, Prof Brian Ripley wrote:

 Sometimes it is better not to document things than try to give precise
 details which may get changed *and* there will be useRs who misread (and
 maybe even file bug reports on their misreadings). The source is the
 ultimate documentation.

 I can't agree with this less. The source does the computation. The
 documentation says how to use it and what it should do. Corner cases
 can be trapped in code or mentioned in Notes. But the source is
 only useful if you can easily find it and then can understand what it is
 doing, particularly for a .Primitive like round().
 The source is only the documentation of last resort.

 I agree. It seems to me that saying that the source is the ultimate
 documentation
 is rather like (in pure mathematics) saying that all maths follows from the
 Zermello-Fraenkel axioms plus the Axiom of Choice, so those axioms are
 all that we
 need to tell anyone.

R is an open source project. That means we expect people to look at the 
source, to answer some of their own questions, to suggest improvements, 
to point out errors. If you don't look at it, you aren't holding up 
your side of the bargain.

Duncan Murdoch

_

R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-10 Thread Michael Friendly

On 10/9/2011 6:18 AM, Prof Brian Ripley wrote:


Sometimes it is better not to document things than try to give precise
details which may get changed *and* there will be useRs who misread (and
maybe even file bug reports on their misreadings). The source is the
ultimate documentation.


I can't agree with this less.  The source does the computation. The 
documentation says how to use it and what it should do.  Corner cases

can be trapped in code or mentioned in Notes.  But the source is
only useful if you can easily find it and then can understand what it is
doing, particularly for a .Primitive like round().
The source is only the documentation of last resort.

-Michael

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-09 Thread Rolf Turner

On 09/10/11 00:18, Duncan Murdoch wrote:

On 11-10-07 5:26 PM, Carl Witthoft wrote:

Just wondering here -- I tested and found to my delight that

%  round(325.4,-2)
[1] 300

gave me exactly what I would have expected (and wanted).  Since it's not
explicitly mentioned in the documentation that negative 'digits' is
allowed, I just wanted to ask whether this behavior is intentional or a
happy turn of events.  I'm always paranoid that something not explicitly
documented might disappear in future revisons.



It is intentional, and one of the regression tests confirms that it's 
there, so it won't disappear by mistake, and would be very unlikely to 
disappear intentionally.


Uh, wouldn't it be *nice* to mention this --- not completely obvious --- 
capability

in the help file?

cheers,

Rolf

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-09 Thread Rolf Turner

On 09/10/11 10:39, Duncan Murdoch wrote:

On 11-10-08 5:32 PM, Rolf Turner wrote:

On 09/10/11 00:18, Duncan Murdoch wrote:

On 11-10-07 5:26 PM, Carl Witthoft wrote:

Just wondering here -- I tested and found to my delight that

%  round(325.4,-2)
[1] 300

gave me exactly what I would have expected (and wanted).  Since 
it's not

explicitly mentioned in the documentation that negative 'digits' is
allowed, I just wanted to ask whether this behavior is intentional 
or a
happy turn of events.  I'm always paranoid that something not 
explicitly

documented might disappear in future revisons.



It is intentional, and one of the regression tests confirms that it's
there, so it won't disappear by mistake, and would be very unlikely to
disappear intentionally.


Uh, wouldn't it be *nice* to mention this --- not completely obvious ---
capability
in the help file?


If we told you all of R's secrets, we'd have to kill you.


Fortune nomination?

cheers,

Rolf

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-09 Thread Ted Harding
On 09-Oct-11 00:46:58, Carl Witthoft wrote:
 
 On 10/8/11 6:11 PM, (Ted Harding) wrote:
 
 Carl Witthoft's serendipitous discovery is a nice example
 of how secrets can be guessed by wondering what if ... ?.
 So probably you don;t need to tell the secrets.

 Taking the negative digits to their logical extreme:

round(654.321,2)
# [1] 654.32
round(654.321,1)
# [1] 654.3
round(654.321,0)
# [1] 654
round(654.321,-1)
# [1] 650
round(654.321,-2)
# [1] 700
round(654.321,-3)
# [1] 1000
round(654.321,-4)
# [1] 0

 which is what you'd logically expect (but is it what you
 would intuitively expect?).

 Oh, oh, somebody's going all metaphysical on us.

Nor should one forget the rounding rules (not OS-dependent
in this case, I think ... ?):

  round(5000,-4)
  # [1] 0
  round(15000,-4)
  # [1] 2

Ted.


E-Mail: (Ted Harding) ted.hard...@wlandres.net
Fax-to-email: +44 (0)870 094 0861
Date: 09-Oct-11   Time: 08:59:58
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-09 Thread Duncan Murdoch

On 11-10-09 4:00 AM, (Ted Harding) wrote:

On 09-Oct-11 00:46:58, Carl Witthoft wrote:


On 10/8/11 6:11 PM, (Ted Harding) wrote:


Carl Witthoft's serendipitous discovery is a nice example
of how secrets can be guessed by wondering what if ... ?.
So probably you don;t need to tell the secrets.

Taking the negative digits to their logical extreme:

round(654.321,2)
# [1] 654.32
round(654.321,1)
# [1] 654.3
round(654.321,0)
# [1] 654
round(654.321,-1)
# [1] 650
round(654.321,-2)
# [1] 700
round(654.321,-3)
# [1] 1000
round(654.321,-4)
# [1] 0

which is what you'd logically expect (but is it what you
would intuitively expect?).


Oh, oh, somebody's going all metaphysical on us.


Nor should one forget the rounding rules (not OS-dependent
in this case, I think ... ?):

   round(5000,-4)
   # [1] 0
   round(15000,-4)
   # [1] 2


The intention is that those are not OS dependent, but since they rely on 
exact representations, there could be differences:  not all platforms 
support the extended real 80 bit intermediate representations.  (If 
you were rounding to 0 d.p., they should all agree on a round to even 
rule.  Rounding to -4 d.p. involves dividing by 10^4, and that could 
lead to errors.)


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-09 Thread Prof Brian Ripley

On Sat, 8 Oct 2011, Duncan Murdoch wrote:


On 11-10-07 5:26 PM, Carl Witthoft wrote:

Just wondering here -- I tested and found to my delight that

%  round(325.4,-2)
[1] 300

gave me exactly what I would have expected (and wanted).  Since it's not
explicitly mentioned in the documentation that negative 'digits' is
allowed, I just wanted to ask whether this behavior is intentional or a
happy turn of events.  I'm always paranoid that something not explicitly
documented might disappear in future revisons.



It is intentional, and one of the regression tests confirms that it's there, 
so it won't disappear by mistake, and would be very unlikely to disappear 
intentionally.


It needs careful documentation though (as do the corner cases of 
signif).  Things like

round(325.4,-3)

[1] 0

signif(325.4,-3)

[1] 300

signif(325.4,0)

[1] 300
may not be what you expect.

Sometimes it is better not to document things than try to give precise 
details which may get changed *and* there will be useRs who misread 
(and maybe even file bug reports on their misreadings).  The source is 
the ultimate documentation.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-08 Thread Duncan Murdoch

On 11-10-07 5:26 PM, Carl Witthoft wrote:

Just wondering here -- I tested and found to my delight that

%  round(325.4,-2)
[1] 300

gave me exactly what I would have expected (and wanted).  Since it's not
explicitly mentioned in the documentation that negative 'digits' is
allowed, I just wanted to ask whether this behavior is intentional or a
happy turn of events.  I'm always paranoid that something not explicitly
documented might disappear in future revisons.



It is intentional, and one of the regression tests confirms that it's 
there, so it won't disappear by mistake, and would be very unlikely to 
disappear intentionally.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-08 Thread Duncan Murdoch

On 11-10-08 5:32 PM, Rolf Turner wrote:

On 09/10/11 00:18, Duncan Murdoch wrote:

On 11-10-07 5:26 PM, Carl Witthoft wrote:

Just wondering here -- I tested and found to my delight that

%  round(325.4,-2)
[1] 300

gave me exactly what I would have expected (and wanted).  Since it's not
explicitly mentioned in the documentation that negative 'digits' is
allowed, I just wanted to ask whether this behavior is intentional or a
happy turn of events.  I'm always paranoid that something not explicitly
documented might disappear in future revisons.



It is intentional, and one of the regression tests confirms that it's
there, so it won't disappear by mistake, and would be very unlikely to
disappear intentionally.


Uh, wouldn't it be *nice* to mention this --- not completely obvious ---
capability
in the help file?


If we told you all of R's secrets, we'd have to kill you.

Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-08 Thread Ted Harding
On 08-Oct-11 21:39:07, Duncan Murdoch wrote:
 On 11-10-08 5:32 PM, Rolf Turner wrote:
 On 09/10/11 00:18, Duncan Murdoch wrote:
 On 11-10-07 5:26 PM, Carl Witthoft wrote:
 Just wondering here -- I tested and found to my delight that

 %  round(325.4,-2)
 [1] 300

 gave me exactly what I would have expected (and wanted).
 Since it's not explicitly mentioned in the documentation
 that negative 'digits' is allowed, I just wanted to ask
 whether this behavior is intentional or a happy turn of
 events. I'm always paranoid that something not explicitly
 documented might disappear in future revisons.

 It is intentional, and one of the regression tests confirms
 that it's there, so it won't disappear by mistake, and would
 be very unlikely to disappear intentionally.

 Uh, wouldn't it be *nice* to mention this --- not completely
 obvious --- capability in the help file?
 
 If we told you all of R's secrets, we'd have to kill you.
 
 Duncan Murdoch

A Fortunate remark??

That being said -- if such are your intentions, then over
my dead body ...

Carl Witthoft's serendipitous discovery is a nice example
of how secrets can be guessed by wondering what if ... ?.
So probably you don;t need to tell the secrets.

Taking the negative digits to their logical extreme:

  round(654.321,2)
  # [1] 654.32
  round(654.321,1)
  # [1] 654.3
  round(654.321,0)
  # [1] 654
  round(654.321,-1)
  # [1] 650
  round(654.321,-2)
  # [1] 700
  round(654.321,-3)
  # [1] 1000
  round(654.321,-4)
  # [1] 0

which is what you'd logically expect (but is it what you
would intuitively expect?).

Ted.


E-Mail: (Ted Harding) ted.hard...@wlandres.net
Fax-to-email: +44 (0)870 094 0861
Date: 08-Oct-11   Time: 23:11:27
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round() and negative digits

2011-10-08 Thread Carl Witthoft



On 10/8/11 6:11 PM, (Ted Harding) wrote:


Carl Witthoft's serendipitous discovery is a nice example
of how secrets can be guessed by wondering what if ... ?.
So probably you don;t need to tell the secrets.

Taking the negative digits to their logical extreme:

   round(654.321,2)
   # [1] 654.32
   round(654.321,1)
   # [1] 654.3
   round(654.321,0)
   # [1] 654
   round(654.321,-1)
   # [1] 650
   round(654.321,-2)
   # [1] 700
   round(654.321,-3)
   # [1] 1000
   round(654.321,-4)
   # [1] 0

which is what you'd logically expect (but is it what you
would intuitively expect?).


Oh, oh, somebody's going all metaphysical on us.


--
-
Sent from my Cray XK6

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.