Re: [Rd] Wishlist: Navigate to "Index" page of help when no topic (PR#13872)

2009-08-04 Thread Romain Francois

Hello,

I'm jumping a bit late on this, but what about something like:

index?survival

or more generally

foo?bar

with the ability for the user/package to define what the combination 
"foo"/"bar" means. At the moment, the way "package?survival" is handled 
is to :

- create the string "package-survival"
- call help with it

Romain



On 08/05/2009 02:10 AM, murd...@stats.uwo.ca wrote:

On 04/08/2009 7:33 PM, Steven McKinney wrote:

-Original Message-
From: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
Sent: Tuesday, August 04, 2009 8:03 AM
To: Steven McKinney
Cc: r-de...@stat.math.ethz.ch; r-b...@r-project.org
Subject: Re: [Rd] Wishlist: Navigate to "Index" page of help when no
topic specified (PR#13860)

On 7/28/2009 6:30 PM, smckin...@bccrc.ca wrote:

Hi all,

When I install a new package, and don't yet know any function names,
I have to play the "poor man's game" to get to the standard
help system "Index" page for the package:

You could complain to the package author or maintainer, who should have
created a help alias with the package name so that ?survival would give
you something useful.  But I would guess R 2.10.x or 2.11.x will do
that
automatically.

Duncan Murdoch

Unfortunately it happens frequently - hopefully I
don't have to complain so much - I'd rather figure
out code to get to the index page!

When you say "I would guess R 2.10.x or 2.11.x will do
that automatically" do you mean
?survival::
or some similar incantation
will take me to the Index or 00Index page?


I would guess package?survival will take you to a help page that is
similar to what you get now in the flat display from
library(help=survival).  Ideally it will have a link on it to the index
page.  It is possible that ?survival will work too; that may be more
controversial, because for many packages (e.g. boot) an alias like that
is already defined, pointing to something other than the package main page.


Do I need to propose code or is it already
known how to do this within the R core group?


I doubt if code to do that would be accepted (since it will be redundant
once the above changes are in place), but posting it to r-devel might
help people in the meantime.  You should look at the tools package,
which has a number of functions that are used by R for constructing the
help pages; there's probably something there that will let you construct
a link to the index fairly easily.

Duncan Murdoch


Best
Steve McKinney



Poor Man's Game -=20
   Load new package;=20
   issue search() command;
   find position (say N) of loaded package;=20
   issue objects(pos =3D N) command;
   get name of a random function (san newFunction);=20
   issue ?newFunction command;
   scroll to bottom of page;=20
   click on the "Index" hyperlink

There are other variations, but they all involve this=20
long march to the Index page.


What I'd like to be able to do is enter the command


help(package =3D "survival")

or


?survival::

and get the usual hyperlinked help page displayed (the "00Index"

page)

instead of the static "text only" display or an error message

(for example, on Windows, this equates to invoking
"C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
on Apple Mac,


"/Library/Frameworks/R.framework/Resources/library/survival/html/00Inde
x.ht=

ml"
etc.)


Details:
---

The help() function returns an object of
class "help_files_with_topic".
The object consists of a character vector
with several attributes.

PC:  Windows XP


library("survival")
foo<- help("aareg", package =3D "survival")
class(foo)

[1] "help_files_with_topic"

foo[1]

[1] "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/aareg"

attributes(foo)

$call
help(topic =3D "aareg", package =3D "survival")

$pager
[1] "internal"

$topic
[1] "aareg"

$tried_all_packages
[1] FALSE

$type
[1] "chm"

$class
[1] "help_files_with_topic"


bar<- help("", package =3D "survival")
class(bar)

[1] "help_files_with_topic"

bar[1]

[1] NA

attributes(bar)

$call
help(topic =3D "", package =3D "survival")

$pager
[1] "internal"

$topic
[1] ""

$tried_all_packages
[1] FALSE

$type
[1] "chm"

$class
[1] "help_files_with_topic"

If I alter the character vector to
point to "00Index"


bar[1]<- "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
bar

I see exactly what I've been attempting to achieve.


Mac OS X:


foo<- help("aareg", package =3D "survival")
foo[1]

[1]

"/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.
=

html"

attributes(foo)

$call
help(topic =3D "aareg", package =3D "survival")

$pager
[1] "/Library/Frameworks/R.framework/Resources/bin/pager"

$topic
[1] "aareg"

$tried_all_packages
[1] FALSE

$type
[1] "html"

$class
[1] "help_files_with_topic"


bar<- help("", package =3D "survival")
bar[1]

[1] NA

bar[1]<-

"/Library/Frameworks/R.framework/Resources/library/survival/htm=

l/00Index.html"

bar

Again I see exactly what I've been after.

Running R in Emacs on Mac OS X:


foo<- help(topic =3D "aareg", package =3D "survival")
foo[1]

Re: [Rd] Wishlist: Navigate to "Index" page of help when no topic (PR#13873)

2009-08-04 Thread smckinney
> -Original Message-
> From: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
> Sent: Tuesday, August 04, 2009 5:06 PM
> To: Steven McKinney
> Cc: 'r-de...@stat.math.ethz.ch'; 'r-b...@r-project.org'
> Subject: Re: [Rd] Wishlist: Navigate to "Index" page of help when no
> topic specified (PR#13860)
>=20
> On 04/08/2009 7:33 PM, Steven McKinney wrote:
> >> -Original Message-
> >> From: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
> >> Sent: Tuesday, August 04, 2009 8:03 AM
> >> To: Steven McKinney
> >> Cc: r-de...@stat.math.ethz.ch; r-b...@r-project.org
> >> Subject: Re: [Rd] Wishlist: Navigate to "Index" page of help when no
> >> topic specified (PR#13860)
> >>
> >> On 7/28/2009 6:30 PM, smckin...@bccrc.ca wrote:
> >>> Hi all,
> >>>
> >>> When I install a new package, and don't yet know any function
> names,
> >>> I have to play the "poor man's game" to get to the standard
> >>> help system "Index" page for the package:
> >> You could complain to the package author or maintainer, who should
> have
> >> created a help alias with the package name so that ?survival would
> give
> >> you something useful.  But I would guess R 2.10.x or 2.11.x will do
> >> that
> >> automatically.
> >>
> >> Duncan Murdoch
> >
> > Unfortunately it happens frequently - hopefully I
> > don't have to complain so much - I'd rather figure
> > out code to get to the index page!
> >
> > When you say "I would guess R 2.10.x or 2.11.x will do
> > that automatically" do you mean
> > ?survival::
> > or some similar incantation
> > will take me to the Index or 00Index page?
>=20
> I would guess package?survival will take you to a help page that is
> similar to what you get now in the flat display from
> library(help=3Dsurvival).  Ideally it will have a link on it to the index
> page.  It is possible that ?survival will work too; that may be more
> controversial, because for many packages (e.g. boot) an alias like that
> is already defined, pointing to something other than the package main
> page.

Yes, package?survival and help(package =3D survival) and ?survival
all are currently in use which is why I propose
?survival::
with no topic after the "::" as an incantation to go to the 00Index page.

>=20
> > Do I need to propose code or is it already
> > known how to do this within the R core group?
>=20
> I doubt if code to do that would be accepted (since it will be
> redundant
> once the above changes are in place), but posting it to r-devel might
> help people in the meantime.  You should look at the tools package,
> which has a number of functions that are used by R for constructing the
> help pages; there's probably something there that will let you
> construct
> a link to the index fairly easily.

Thanks for the information.  I'll review package tools and
work out some demonstrative code.

>=20
> Duncan Murdoch
>=20
> > Best
> > Steve McKinney
> >
> >
> >>> Poor Man's Game -=3D20
> >>>   Load new package;=3D20
> >>>   issue search() command;
> >>>   find position (say N) of loaded package;=3D20
> >>>   issue objects(pos =3D3D N) command;
> >>>   get name of a random function (san newFunction);=3D20
> >>>   issue ?newFunction command;
> >>>   scroll to bottom of page;=3D20
> >>>   click on the "Index" hyperlink
> >>>
> >>> There are other variations, but they all involve this=3D20
> >>> long march to the Index page.
> >>>
> >>>
> >>> What I'd like to be able to do is enter the command
> >>>
>  help(package =3D3D "survival")
> >>> or
> >>>
>  ?survival::
> >>> and get the usual hyperlinked help page displayed (the "00Index"
> >> page)
> >>> instead of the static "text only" display or an error message
> >>>
> >>> (for example, on Windows, this equates to invoking
> >>> "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
> >>> on Apple Mac,
> >>>
> >>
> "/Library/Frameworks/R.framework/Resources/library/survival/html/00Inde
> >> x.ht=3D
> >>> ml"
> >>> etc.)
> >>>
> >>>
> >>> Details:
> >>> ---
> >>>
> >>> The help() function returns an object of
> >>> class "help_files_with_topic".
> >>> The object consists of a character vector
> >>> with several attributes.
> >>>
> >>> PC:  Windows XP
> >>>
>  library("survival")
>  foo <- help("aareg", package =3D3D "survival")
>  class(foo)
> >>> [1] "help_files_with_topic"
>  foo[1]
> >>> [1] "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/aareg"
>  attributes(foo)
> >>> $call
> >>> help(topic =3D3D "aareg", package =3D3D "survival")
> >>>
> >>> $pager
> >>> [1] "internal"
> >>>
> >>> $topic
> >>> [1] "aareg"
> >>>
> >>> $tried_all_packages
> >>> [1] FALSE
> >>>
> >>> $type
> >>> [1] "chm"
> >>>
> >>> $class
> >>> [1] "help_files_with_topic"
> >>>
>  bar <- help("", package =3D3D "survival")
>  class(bar)
> >>> [1] "help_files_with_topic"
>  bar[1]
> >>> [1] NA
>  attributes(bar)
> >>> $call
> >>> help(topic =3D3D "", package =3D3D "survival")
> >>>
> >>> $pager
> >>> [1] "internal"
> >>>
> >>> $topic
> >>> [1] ""
> >>>
> >>> $tried_all

Re: [Rd] Advice sought about Rd versions

2009-08-04 Thread Duncan Murdoch

On 28/07/2009 1:21 PM, Michael Dewey wrote:
 From R 2.9.0 we have the concept of versions for Rd files. The 
manual is clear about the differences but I am unsure as to what I 
should do about my existing packages. Is it recommended that I set 
the version to 1.1 and then fix the errors R CMD check helpfully 
points out and then subsequently do the same for later versions (the 
manual mentions version 2 is coming)? What benefit will I gain?


This is currently somewhat in flux.  Ask again in a couple of weeks.

(My preference is that \Rdversion specifies a minimum version needed, so 
it's mostly redundant:  the DESCRIPTION file could be used to say the 
version of R needed, and Rd versions are going to change more slowly 
than R versions.  But as I said, this is in flux.)


Duncan Murdoch

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


Re: [Rd] Wishlist: Navigate to "Index" page of help when no topic specified (PR#13860)

2009-08-04 Thread Steven McKinney
> -Original Message-
> From: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
> Sent: Tuesday, August 04, 2009 5:06 PM
> To: Steven McKinney
> Cc: 'r-de...@stat.math.ethz.ch'; 'r-b...@r-project.org'
> Subject: Re: [Rd] Wishlist: Navigate to "Index" page of help when no
> topic specified (PR#13860)
> 
> On 04/08/2009 7:33 PM, Steven McKinney wrote:
> >> -Original Message-
> >> From: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
> >> Sent: Tuesday, August 04, 2009 8:03 AM
> >> To: Steven McKinney
> >> Cc: r-de...@stat.math.ethz.ch; r-b...@r-project.org
> >> Subject: Re: [Rd] Wishlist: Navigate to "Index" page of help when no
> >> topic specified (PR#13860)
> >>
> >> On 7/28/2009 6:30 PM, smckin...@bccrc.ca wrote:
> >>> Hi all,
> >>>
> >>> When I install a new package, and don't yet know any function
> names,
> >>> I have to play the "poor man's game" to get to the standard
> >>> help system "Index" page for the package:
> >> You could complain to the package author or maintainer, who should
> have
> >> created a help alias with the package name so that ?survival would
> give
> >> you something useful.  But I would guess R 2.10.x or 2.11.x will do
> >> that
> >> automatically.
> >>
> >> Duncan Murdoch
> >
> > Unfortunately it happens frequently - hopefully I
> > don't have to complain so much - I'd rather figure
> > out code to get to the index page!
> >
> > When you say "I would guess R 2.10.x or 2.11.x will do
> > that automatically" do you mean
> > ?survival::
> > or some similar incantation
> > will take me to the Index or 00Index page?
> 
> I would guess package?survival will take you to a help page that is
> similar to what you get now in the flat display from
> library(help=survival).  Ideally it will have a link on it to the index
> page.  It is possible that ?survival will work too; that may be more
> controversial, because for many packages (e.g. boot) an alias like that
> is already defined, pointing to something other than the package main
> page.

Yes, package?survival and help(package = survival) and ?survival
all are currently in use which is why I propose
?survival::
with no topic after the "::" as an incantation to go to the 00Index page.

> 
> > Do I need to propose code or is it already
> > known how to do this within the R core group?
> 
> I doubt if code to do that would be accepted (since it will be
> redundant
> once the above changes are in place), but posting it to r-devel might
> help people in the meantime.  You should look at the tools package,
> which has a number of functions that are used by R for constructing the
> help pages; there's probably something there that will let you
> construct
> a link to the index fairly easily.

Thanks for the information.  I'll review package tools and
work out some demonstrative code.

> 
> Duncan Murdoch
> 
> > Best
> > Steve McKinney
> >
> >
> >>> Poor Man's Game -=20
> >>>   Load new package;=20
> >>>   issue search() command;
> >>>   find position (say N) of loaded package;=20
> >>>   issue objects(pos =3D N) command;
> >>>   get name of a random function (san newFunction);=20
> >>>   issue ?newFunction command;
> >>>   scroll to bottom of page;=20
> >>>   click on the "Index" hyperlink
> >>>
> >>> There are other variations, but they all involve this=20
> >>> long march to the Index page.
> >>>
> >>>
> >>> What I'd like to be able to do is enter the command
> >>>
>  help(package =3D "survival")
> >>> or
> >>>
>  ?survival::
> >>> and get the usual hyperlinked help page displayed (the "00Index"
> >> page)
> >>> instead of the static "text only" display or an error message
> >>>
> >>> (for example, on Windows, this equates to invoking
> >>> "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
> >>> on Apple Mac,
> >>>
> >>
> "/Library/Frameworks/R.framework/Resources/library/survival/html/00Inde
> >> x.ht=
> >>> ml"
> >>> etc.)
> >>>
> >>>
> >>> Details:
> >>> ---
> >>>
> >>> The help() function returns an object of
> >>> class "help_files_with_topic".
> >>> The object consists of a character vector
> >>> with several attributes.
> >>>
> >>> PC:  Windows XP
> >>>
>  library("survival")
>  foo <- help("aareg", package =3D "survival")
>  class(foo)
> >>> [1] "help_files_with_topic"
>  foo[1]
> >>> [1] "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/aareg"
>  attributes(foo)
> >>> $call
> >>> help(topic =3D "aareg", package =3D "survival")
> >>>
> >>> $pager
> >>> [1] "internal"
> >>>
> >>> $topic
> >>> [1] "aareg"
> >>>
> >>> $tried_all_packages
> >>> [1] FALSE
> >>>
> >>> $type
> >>> [1] "chm"
> >>>
> >>> $class
> >>> [1] "help_files_with_topic"
> >>>
>  bar <- help("", package =3D "survival")
>  class(bar)
> >>> [1] "help_files_with_topic"
>  bar[1]
> >>> [1] NA
>  attributes(bar)
> >>> $call
> >>> help(topic =3D "", package =3D "survival")
> >>>
> >>> $pager
> >>> [1] "internal"
> >>>
> >>> $topic
> >>> [1] ""
> >>>
> >>> $tried_all_packages
> >>> [1] FALSE
> >>>
> >>> $type
> 

Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-04 Thread John Nolan

Ravi,

There has been a lot of chatter about this, and people don't seem to be
reading carefully.  Perhaps this will help clarify things.

The problem appears to be that R was evaluating x^2 not as multiplication
x*x, but as x^2.0=exp(2.0*log(x)), using standard C functions for the
complex log and exponentiation.  Apparently the C library functions for
this have some inaccuracies in it, which showed up in your calculations.

One of the other responders said that matlab, octave, etc. detect the case
when there is a positive integer power and use multiplication to evaluate.
It appears that Martin Maechler has now submitted a change to R to detect
integer powers and evaluate them via repeated multiplication, which should
eliminate your problem.

There is no guarantee that R or matlab or any other program will evaluate
every expression correctly.  matlab has many years of use and evaluation
that have guided them in correct problems.  R is catching up, but not there
yet.  We are all part of improving R; your question led to a careful
examination of the issue and a fix within a few days.  No commercial
company responds so quickly!

HTH, John

...

John P. Nolan
Math/Stat Department
227 Gray Hall
American University
4400 Massachusetts Avenue, NW
Washington, DC 20016-8050

jpno...@american.edu
202.885.3140 voice
202.885.3155 fax
http://academic2.american.edu/~jpnolan
...



-r-devel-boun...@r-project.org wrote: -


To: "'Martin Becker'" 
From: "Ravi Varadhan" 
Sent by: r-devel-boun...@r-project.org
Date: 08/04/2009 10:59AM
cc: hwborch...@googlemail.com, r-de...@stat.math.ethz.ch
Subject: Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

Please forgive me for my lack of understanding of IEEE floating-point
arithmetic.  I have a hard time undertsanding why "this is not a problem of
R itself", when "ALL" the other well known computing environments including
Matlab, Octave, S+, and Scilab provide accurate results.  My concern is not
really about the "overall" accuracy of R, but just about the complex
arithmetic.  Is there something idiosyncratic about the complex arithmetic?


I am really hoping that some one from the R core would speak up and address
this issue.  It would be a loss to the R users if this fascinating idea of
"complex-step derivative" could not be implemented in R.

Thanks,
Ravi.



---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h

tml








-Original Message-
From: Martin Becker [mailto:martin.bec...@mx.uni-saarland.de]
Sent: Tuesday, August 04, 2009 7:34 AM
To: Ravi Varadhan
Cc: r-de...@stat.math.ethz.ch; hwborch...@googlemail.com
Subject: Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

Dear Ravi,

I suspect that, in general, you may be facing the limitations of machine
accuracy (more precisely, IEEE 754 arithmetics on [64-bit] doubles) in your
application. This is not a problem of R itself, but rather a problem of
standard arithmetics provided by underlying C compilers/CPUs.
In fact, every operation in IEEE arithmetics (so, this is not really a
problem only for complex numbers) may suffer from inexactness, a
particularly difficult one is addition/subtraction. Consider the following
example for real numbers (I know, it is not a very good one...):
The two functions

badfn <- function(x) 1-(1+x)*(1-x)
goodfn <- function(x) x^2

both calculate x^2 (theoretically, given perfect arithmetic). So, as you
want to allow the user to 'specify the mathematical function ... in "any"
form the user chooses', both functions should be ok.
But, unfortunately:

 > badfn(1e-8)
[1] 2.220446049250313e-16
 > goodfn(1e-8)
[1] 1e-16

I don't know what happens in matlab/octave/scilab for this example. They
may
do better, but probably at some cost (dropping IEEE arithmetic/do "clever"
calculations should result in massive speed penalties, try
evaluating   hypergeom([1,-99.9],[-49.9-24.9*I],(1+1.71*I)/2);   in
Maple...).
Now, you have some options:

- assume, that the user is aware of the numerical inexactness of ieee
arithmetics and that he is able to supply some "robust" version of the
mathematical function.
- use some other software (eg., matlab) for the critical calculations
(there
is a R <-> Matlab interface, see package R.matlab on CRAN), if you are
sure,
that this helps.
- implement/use multiple precision arithmetics within R (Martin Maechler's
Rmpfr package may be very useful:
http://r-forge.r-project.org/projec

Re: [Rd] Wishlist: Navigate to "Index" page of help when no topic (PR#13872)

2009-08-04 Thread murdoch
On 04/08/2009 7:33 PM, Steven McKinney wrote:
>> -Original Message-
>> From: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
>> Sent: Tuesday, August 04, 2009 8:03 AM
>> To: Steven McKinney
>> Cc: r-de...@stat.math.ethz.ch; r-b...@r-project.org
>> Subject: Re: [Rd] Wishlist: Navigate to "Index" page of help when no
>> topic specified (PR#13860)
>>
>> On 7/28/2009 6:30 PM, smckin...@bccrc.ca wrote:
>>> Hi all,
>>>
>>> When I install a new package, and don't yet know any function names,
>>> I have to play the "poor man's game" to get to the standard
>>> help system "Index" page for the package:
>> You could complain to the package author or maintainer, who should have
>> created a help alias with the package name so that ?survival would give
>> you something useful.  But I would guess R 2.10.x or 2.11.x will do
>> that
>> automatically.
>>
>> Duncan Murdoch
> 
> Unfortunately it happens frequently - hopefully I
> don't have to complain so much - I'd rather figure
> out code to get to the index page!  
> 
> When you say "I would guess R 2.10.x or 2.11.x will do
> that automatically" do you mean
> ?survival::
> or some similar incantation
> will take me to the Index or 00Index page?

I would guess package?survival will take you to a help page that is 
similar to what you get now in the flat display from 
library(help=survival).  Ideally it will have a link on it to the index 
page.  It is possible that ?survival will work too; that may be more 
controversial, because for many packages (e.g. boot) an alias like that 
is already defined, pointing to something other than the package main page.

> Do I need to propose code or is it already
> known how to do this within the R core group?

I doubt if code to do that would be accepted (since it will be redundant 
once the above changes are in place), but posting it to r-devel might 
help people in the meantime.  You should look at the tools package, 
which has a number of functions that are used by R for constructing the 
help pages; there's probably something there that will let you construct 
a link to the index fairly easily.

Duncan Murdoch

> Best
> Steve McKinney
> 
> 
>>> Poor Man's Game -=20
>>>   Load new package;=20
>>>   issue search() command;
>>>   find position (say N) of loaded package;=20
>>>   issue objects(pos =3D N) command;
>>>   get name of a random function (san newFunction);=20
>>>   issue ?newFunction command;
>>>   scroll to bottom of page;=20
>>>   click on the "Index" hyperlink
>>>
>>> There are other variations, but they all involve this=20
>>> long march to the Index page.
>>>
>>>
>>> What I'd like to be able to do is enter the command
>>>
 help(package =3D "survival")
>>> or
>>>
 ?survival::
>>> and get the usual hyperlinked help page displayed (the "00Index"
>> page)
>>> instead of the static "text only" display or an error message
>>>
>>> (for example, on Windows, this equates to invoking
>>> "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
>>> on Apple Mac,
>>>
>> "/Library/Frameworks/R.framework/Resources/library/survival/html/00Inde
>> x.ht=
>>> ml"
>>> etc.)
>>>
>>>
>>> Details:
>>> ---
>>>
>>> The help() function returns an object of
>>> class "help_files_with_topic".
>>> The object consists of a character vector
>>> with several attributes.
>>>
>>> PC:  Windows XP
>>>
 library("survival")
 foo <- help("aareg", package =3D "survival")
 class(foo)
>>> [1] "help_files_with_topic"
 foo[1]
>>> [1] "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/aareg"
 attributes(foo)
>>> $call
>>> help(topic =3D "aareg", package =3D "survival")
>>>
>>> $pager
>>> [1] "internal"
>>>
>>> $topic
>>> [1] "aareg"
>>>
>>> $tried_all_packages
>>> [1] FALSE
>>>
>>> $type
>>> [1] "chm"
>>>
>>> $class
>>> [1] "help_files_with_topic"
>>>
 bar <- help("", package =3D "survival")
 class(bar)
>>> [1] "help_files_with_topic"
 bar[1]
>>> [1] NA
 attributes(bar)
>>> $call
>>> help(topic =3D "", package =3D "survival")
>>>
>>> $pager
>>> [1] "internal"
>>>
>>> $topic
>>> [1] ""
>>>
>>> $tried_all_packages
>>> [1] FALSE
>>>
>>> $type
>>> [1] "chm"
>>>
>>> $class
>>> [1] "help_files_with_topic"
>>>
>>> If I alter the character vector to
>>> point to "00Index"
>>>
 bar[1] <- "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
 bar
>>> I see exactly what I've been attempting to achieve.
>>>
>>>
>>> Mac OS X:
>>>
 foo <- help("aareg", package =3D "survival")
 foo[1]
>>> [1]
>> "/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.
>> =
>>> html"
 attributes(foo)
>>> $call
>>> help(topic =3D "aareg", package =3D "survival")
>>>
>>> $pager
>>> [1] "/Library/Frameworks/R.framework/Resources/bin/pager"
>>>
>>> $topic
>>> [1] "aareg"
>>>
>>> $tried_all_packages
>>> [1] FALSE
>>>
>>> $type
>>> [1] "html"
>>>
>>> $class
>>> [1] "help_files_with_topic"
>>>
 bar <- help("", package =3D "survival")
 bar[1]
>>> [1] NA
 bar[1] <-
>> "/Library/Frameworks/R.framework/Resourc

Re: [Rd] Wishlist: Navigate to "Index" page of help when no topic specified (PR#13860)

2009-08-04 Thread Duncan Murdoch

On 04/08/2009 7:33 PM, Steven McKinney wrote:

-Original Message-
From: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
Sent: Tuesday, August 04, 2009 8:03 AM
To: Steven McKinney
Cc: r-de...@stat.math.ethz.ch; r-b...@r-project.org
Subject: Re: [Rd] Wishlist: Navigate to "Index" page of help when no
topic specified (PR#13860)

On 7/28/2009 6:30 PM, smckin...@bccrc.ca wrote:

Hi all,

When I install a new package, and don't yet know any function names,
I have to play the "poor man's game" to get to the standard
help system "Index" page for the package:

You could complain to the package author or maintainer, who should have
created a help alias with the package name so that ?survival would give
you something useful.  But I would guess R 2.10.x or 2.11.x will do
that
automatically.

Duncan Murdoch


Unfortunately it happens frequently - hopefully I
don't have to complain so much - I'd rather figure
out code to get to the index page!  


When you say "I would guess R 2.10.x or 2.11.x will do
that automatically" do you mean
?survival::
or some similar incantation
will take me to the Index or 00Index page?


I would guess package?survival will take you to a help page that is 
similar to what you get now in the flat display from 
library(help=survival).  Ideally it will have a link on it to the index 
page.  It is possible that ?survival will work too; that may be more 
controversial, because for many packages (e.g. boot) an alias like that 
is already defined, pointing to something other than the package main page.



Do I need to propose code or is it already
known how to do this within the R core group?


I doubt if code to do that would be accepted (since it will be redundant 
once the above changes are in place), but posting it to r-devel might 
help people in the meantime.  You should look at the tools package, 
which has a number of functions that are used by R for constructing the 
help pages; there's probably something there that will let you construct 
a link to the index fairly easily.


Duncan Murdoch


Best
Steve McKinney



Poor Man's Game -=20
  Load new package;=20
  issue search() command;
  find position (say N) of loaded package;=20
  issue objects(pos =3D N) command;
  get name of a random function (san newFunction);=20
  issue ?newFunction command;
  scroll to bottom of page;=20
  click on the "Index" hyperlink

There are other variations, but they all involve this=20
long march to the Index page.


What I'd like to be able to do is enter the command


help(package =3D "survival")

or


?survival::

and get the usual hyperlinked help page displayed (the "00Index"

page)

instead of the static "text only" display or an error message

(for example, on Windows, this equates to invoking
"C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
on Apple Mac,


"/Library/Frameworks/R.framework/Resources/library/survival/html/00Inde
x.ht=

ml"
etc.)


Details:
---

The help() function returns an object of
class "help_files_with_topic".
The object consists of a character vector
with several attributes.

PC:  Windows XP


library("survival")
foo <- help("aareg", package =3D "survival")
class(foo)

[1] "help_files_with_topic"

foo[1]

[1] "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/aareg"

attributes(foo)

$call
help(topic =3D "aareg", package =3D "survival")

$pager
[1] "internal"

$topic
[1] "aareg"

$tried_all_packages
[1] FALSE

$type
[1] "chm"

$class
[1] "help_files_with_topic"


bar <- help("", package =3D "survival")
class(bar)

[1] "help_files_with_topic"

bar[1]

[1] NA

attributes(bar)

$call
help(topic =3D "", package =3D "survival")

$pager
[1] "internal"

$topic
[1] ""

$tried_all_packages
[1] FALSE

$type
[1] "chm"

$class
[1] "help_files_with_topic"

If I alter the character vector to
point to "00Index"


bar[1] <- "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
bar

I see exactly what I've been attempting to achieve.


Mac OS X:


foo <- help("aareg", package =3D "survival")
foo[1]

[1]

"/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.
=

html"

attributes(foo)

$call
help(topic =3D "aareg", package =3D "survival")

$pager
[1] "/Library/Frameworks/R.framework/Resources/bin/pager"

$topic
[1] "aareg"

$tried_all_packages
[1] FALSE

$type
[1] "html"

$class
[1] "help_files_with_topic"


bar <- help("", package =3D "survival")
bar[1]

[1] NA

bar[1] <-

"/Library/Frameworks/R.framework/Resources/library/survival/htm=

l/00Index.html"

bar

Again I see exactly what I've been after.

Running R in Emacs on Mac OS X:


foo <- help(topic =3D "aareg", package =3D "survival")
foo[1]

[1]

"/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.
=

html"

attributes(foo)

$call
help(topic =3D "aareg", package =3D "survival")

$pager
[1] "/Library/Frameworks/R.framework/Resources/bin/pager"

$topic
[1] "aareg"

$tried_all_packages
[1] FALSE

$type
[1] "html"

$class
[1] "help_files_with_topic"


bar <- help(topic =3D "", package =3D "survi

Re: [Rd] Wishlist: Navigate to "Index" page of help when no topic (PR#13871)

2009-08-04 Thread smckinney

> -Original Message-
> From: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
> Sent: Tuesday, August 04, 2009 8:03 AM
> To: Steven McKinney
> Cc: r-de...@stat.math.ethz.ch; r-b...@r-project.org
> Subject: Re: [Rd] Wishlist: Navigate to "Index" page of help when no
> topic specified (PR#13860)
>=20
> On 7/28/2009 6:30 PM, smckin...@bccrc.ca wrote:
> > Hi all,
> >
> > When I install a new package, and don't yet know any function names,
> > I have to play the "poor man's game" to get to the standard
> > help system "Index" page for the package:
>=20
> You could complain to the package author or maintainer, who should have
> created a help alias with the package name so that ?survival would give
> you something useful.  But I would guess R 2.10.x or 2.11.x will do
> that
> automatically.
>=20
> Duncan Murdoch

Unfortunately it happens frequently - hopefully I
don't have to complain so much - I'd rather figure
out code to get to the index page! =20

When you say "I would guess R 2.10.x or 2.11.x will do
that automatically" do you mean
?survival::
or some similar incantation
will take me to the Index or 00Index page?

Do I need to propose code or is it already
known how to do this within the R core group?

Best
Steve McKinney


>=20
> > Poor Man's Game -=3D20
> >   Load new package;=3D20
> >   issue search() command;
> >   find position (say N) of loaded package;=3D20
> >   issue objects(pos =3D3D N) command;
> >   get name of a random function (san newFunction);=3D20
> >   issue ?newFunction command;
> >   scroll to bottom of page;=3D20
> >   click on the "Index" hyperlink
> >
> > There are other variations, but they all involve this=3D20
> > long march to the Index page.
> >
> >
> > What I'd like to be able to do is enter the command
> >
> >> help(package =3D3D "survival")
> >
> > or
> >
> >> ?survival::
> >
> > and get the usual hyperlinked help page displayed (the "00Index"
> page)
> > instead of the static "text only" display or an error message
> >
> > (for example, on Windows, this equates to invoking
> > "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
> > on Apple Mac,
> >
> "/Library/Frameworks/R.framework/Resources/library/survival/html/00Inde
> x.ht=3D
> > ml"
> > etc.)
> >
> >
> > Details:
> > ---
> >
> > The help() function returns an object of
> > class "help_files_with_topic".
> > The object consists of a character vector
> > with several attributes.
> >
> > PC:  Windows XP
> >
> >> library("survival")
> >> foo <- help("aareg", package =3D3D "survival")
> >> class(foo)
> > [1] "help_files_with_topic"
> >> foo[1]
> > [1] "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/aareg"
> >> attributes(foo)
> > $call
> > help(topic =3D3D "aareg", package =3D3D "survival")
> >
> > $pager
> > [1] "internal"
> >
> > $topic
> > [1] "aareg"
> >
> > $tried_all_packages
> > [1] FALSE
> >
> > $type
> > [1] "chm"
> >
> > $class
> > [1] "help_files_with_topic"
> >
> >> bar <- help("", package =3D3D "survival")
> >> class(bar)
> > [1] "help_files_with_topic"
> >> bar[1]
> > [1] NA
> >> attributes(bar)
> > $call
> > help(topic =3D3D "", package =3D3D "survival")
> >
> > $pager
> > [1] "internal"
> >
> > $topic
> > [1] ""
> >
> > $tried_all_packages
> > [1] FALSE
> >
> > $type
> > [1] "chm"
> >
> > $class
> > [1] "help_files_with_topic"
> >
> > If I alter the character vector to
> > point to "00Index"
> >
> >> bar[1] <- "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
> >> bar
> >
> > I see exactly what I've been attempting to achieve.
> >
> >
> > Mac OS X:
> >
> >> foo <- help("aareg", package =3D3D "survival")
> >> foo[1]
> > [1]
> "/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.
> =3D
> > html"
> >> attributes(foo)
> > $call
> > help(topic =3D3D "aareg", package =3D3D "survival")
> >
> > $pager
> > [1] "/Library/Frameworks/R.framework/Resources/bin/pager"
> >
> > $topic
> > [1] "aareg"
> >
> > $tried_all_packages
> > [1] FALSE
> >
> > $type
> > [1] "html"
> >
> > $class
> > [1] "help_files_with_topic"
> >
> >> bar <- help("", package =3D3D "survival")
> >> bar[1]
> > [1] NA
> >> bar[1] <-
> "/Library/Frameworks/R.framework/Resources/library/survival/htm=3D
> > l/00Index.html"
> >> bar
> >
> > Again I see exactly what I've been after.
> >
> > Running R in Emacs on Mac OS X:
> >
> >> foo <- help(topic =3D3D "aareg", package =3D3D "survival")
> >> foo[1]
> > [1]
> "/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.
> =3D
> > html"
> >> attributes(foo)
> > $call
> > help(topic =3D3D "aareg", package =3D3D "survival")
> >
> > $pager
> > [1] "/Library/Frameworks/R.framework/Resources/bin/pager"
> >
> > $topic
> > [1] "aareg"
> >
> > $tried_all_packages
> > [1] FALSE
> >
> > $type
> > [1] "html"
> >
> > $class
> > [1] "help_files_with_topic"
> >
> >> bar <- help(topic =3D3D "", package =3D3D "survival")
> >> bar[1]
> > [1] NA
> >> bar[1] <-
> "/Library/Frameworks/R.framework/Resources/library/survival/htm=3D
> > l/00Index.html"
> >> bar
> > Help for '' is sho

Re: [Rd] Wishlist: Navigate to "Index" page of help when no topic specified (PR#13860)

2009-08-04 Thread Steven McKinney

> -Original Message-
> From: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
> Sent: Tuesday, August 04, 2009 8:03 AM
> To: Steven McKinney
> Cc: r-de...@stat.math.ethz.ch; r-b...@r-project.org
> Subject: Re: [Rd] Wishlist: Navigate to "Index" page of help when no
> topic specified (PR#13860)
> 
> On 7/28/2009 6:30 PM, smckin...@bccrc.ca wrote:
> > Hi all,
> >
> > When I install a new package, and don't yet know any function names,
> > I have to play the "poor man's game" to get to the standard
> > help system "Index" page for the package:
> 
> You could complain to the package author or maintainer, who should have
> created a help alias with the package name so that ?survival would give
> you something useful.  But I would guess R 2.10.x or 2.11.x will do
> that
> automatically.
> 
> Duncan Murdoch

Unfortunately it happens frequently - hopefully I
don't have to complain so much - I'd rather figure
out code to get to the index page!  

When you say "I would guess R 2.10.x or 2.11.x will do
that automatically" do you mean
?survival::
or some similar incantation
will take me to the Index or 00Index page?

Do I need to propose code or is it already
known how to do this within the R core group?

Best
Steve McKinney


> 
> > Poor Man's Game -=20
> >   Load new package;=20
> >   issue search() command;
> >   find position (say N) of loaded package;=20
> >   issue objects(pos =3D N) command;
> >   get name of a random function (san newFunction);=20
> >   issue ?newFunction command;
> >   scroll to bottom of page;=20
> >   click on the "Index" hyperlink
> >
> > There are other variations, but they all involve this=20
> > long march to the Index page.
> >
> >
> > What I'd like to be able to do is enter the command
> >
> >> help(package =3D "survival")
> >
> > or
> >
> >> ?survival::
> >
> > and get the usual hyperlinked help page displayed (the "00Index"
> page)
> > instead of the static "text only" display or an error message
> >
> > (for example, on Windows, this equates to invoking
> > "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
> > on Apple Mac,
> >
> "/Library/Frameworks/R.framework/Resources/library/survival/html/00Inde
> x.ht=
> > ml"
> > etc.)
> >
> >
> > Details:
> > ---
> >
> > The help() function returns an object of
> > class "help_files_with_topic".
> > The object consists of a character vector
> > with several attributes.
> >
> > PC:  Windows XP
> >
> >> library("survival")
> >> foo <- help("aareg", package =3D "survival")
> >> class(foo)
> > [1] "help_files_with_topic"
> >> foo[1]
> > [1] "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/aareg"
> >> attributes(foo)
> > $call
> > help(topic =3D "aareg", package =3D "survival")
> >
> > $pager
> > [1] "internal"
> >
> > $topic
> > [1] "aareg"
> >
> > $tried_all_packages
> > [1] FALSE
> >
> > $type
> > [1] "chm"
> >
> > $class
> > [1] "help_files_with_topic"
> >
> >> bar <- help("", package =3D "survival")
> >> class(bar)
> > [1] "help_files_with_topic"
> >> bar[1]
> > [1] NA
> >> attributes(bar)
> > $call
> > help(topic =3D "", package =3D "survival")
> >
> > $pager
> > [1] "internal"
> >
> > $topic
> > [1] ""
> >
> > $tried_all_packages
> > [1] FALSE
> >
> > $type
> > [1] "chm"
> >
> > $class
> > [1] "help_files_with_topic"
> >
> > If I alter the character vector to
> > point to "00Index"
> >
> >> bar[1] <- "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
> >> bar
> >
> > I see exactly what I've been attempting to achieve.
> >
> >
> > Mac OS X:
> >
> >> foo <- help("aareg", package =3D "survival")
> >> foo[1]
> > [1]
> "/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.
> =
> > html"
> >> attributes(foo)
> > $call
> > help(topic =3D "aareg", package =3D "survival")
> >
> > $pager
> > [1] "/Library/Frameworks/R.framework/Resources/bin/pager"
> >
> > $topic
> > [1] "aareg"
> >
> > $tried_all_packages
> > [1] FALSE
> >
> > $type
> > [1] "html"
> >
> > $class
> > [1] "help_files_with_topic"
> >
> >> bar <- help("", package =3D "survival")
> >> bar[1]
> > [1] NA
> >> bar[1] <-
> "/Library/Frameworks/R.framework/Resources/library/survival/htm=
> > l/00Index.html"
> >> bar
> >
> > Again I see exactly what I've been after.
> >
> > Running R in Emacs on Mac OS X:
> >
> >> foo <- help(topic =3D "aareg", package =3D "survival")
> >> foo[1]
> > [1]
> "/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.
> =
> > html"
> >> attributes(foo)
> > $call
> > help(topic =3D "aareg", package =3D "survival")
> >
> > $pager
> > [1] "/Library/Frameworks/R.framework/Resources/bin/pager"
> >
> > $topic
> > [1] "aareg"
> >
> > $tried_all_packages
> > [1] FALSE
> >
> > $type
> > [1] "html"
> >
> > $class
> > [1] "help_files_with_topic"
> >
> >> bar <- help(topic =3D "", package =3D "survival")
> >> bar[1]
> > [1] NA
> >> bar[1] <-
> "/Library/Frameworks/R.framework/Resources/library/survival/htm=
> > l/00Index.html"
> >> bar
> > Help for '' is shown in browser /usr/bin/open ...
> > Use
> > help("", htmlhel

Re: [Rd] Accuracy (PR#13867)

2009-08-04 Thread Greg . Snow
What research into this problem did you do that failed to turn up FAQ 7.31?

--=20
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-devel-boun...@r-project.org [mailto:r-devel-boun...@r-
> project.org] On Behalf Of lueth...@student.ethz.ch
> Sent: Tuesday, August 04, 2009 8:25 AM
> To: r-de...@stat.math.ethz.ch
> Cc: r-b...@r-project.org
> Subject: [Rd] Accuracy (PR#13867)
>=20
> Full_Name: Manuel Luethi
> Version: 2.9.1
> OS: Windows XP
> Submission from: (NULL) (129.132.128.136)
>=20
>=20
> Hi
>=20
> I created the following vectors:
>=20
> p_1=3Dc(0.2,0.2,0.2,0.2,0.1,0.25,0.4,0.1,0.25,0.4,0.1,0.25,0.4,0.1,0.25,0
> .4,0.2,0.5,0.8,0.2,0.5,0.8,0.2,0.5,0.8,0.2,0.5,0.8)
> p_2=3Dc(0,0,0,0,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.4,0.25,
> 0.1,0.4,0.25,0.1,0.4,0.25,0.1,0.4,0.25,0.1)
>=20
> As these are probabilities, I calculated the remainder as
>=20
> p_3=3D1-p_1-p_2
>=20
> There the values which ought to be 0.1 were lateron not recognised by
> p_3=3D=3D0.1,
> but only if I used p_3 <=3D 0.1.
>=20
> The full calculation is actually bigger but the core issue remains: I
> used
> values input by hand, built a difference and it was wrong.
>=20
> I know that exactly the value 0.1 is one that can not be represented
> using
> binary rep. Maybe that's it, maybe not. Just wanted to let you know.
>=20
> With kind regards
>=20
> Manuel
>=20
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

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


Re: [Rd] Accuracy (PR#13867)

2009-08-04 Thread Greg Snow
What research into this problem did you do that failed to turn up FAQ 7.31?

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-devel-boun...@r-project.org [mailto:r-devel-boun...@r-
> project.org] On Behalf Of lueth...@student.ethz.ch
> Sent: Tuesday, August 04, 2009 8:25 AM
> To: r-de...@stat.math.ethz.ch
> Cc: r-b...@r-project.org
> Subject: [Rd] Accuracy (PR#13867)
> 
> Full_Name: Manuel Luethi
> Version: 2.9.1
> OS: Windows XP
> Submission from: (NULL) (129.132.128.136)
> 
> 
> Hi
> 
> I created the following vectors:
> 
> p_1=c(0.2,0.2,0.2,0.2,0.1,0.25,0.4,0.1,0.25,0.4,0.1,0.25,0.4,0.1,0.25,0
> .4,0.2,0.5,0.8,0.2,0.5,0.8,0.2,0.5,0.8,0.2,0.5,0.8)
> p_2=c(0,0,0,0,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.4,0.25,
> 0.1,0.4,0.25,0.1,0.4,0.25,0.1,0.4,0.25,0.1)
> 
> As these are probabilities, I calculated the remainder as
> 
> p_3=1-p_1-p_2
> 
> There the values which ought to be 0.1 were lateron not recognised by
> p_3==0.1,
> but only if I used p_3 <= 0.1.
> 
> The full calculation is actually bigger but the core issue remains: I
> used
> values input by hand, built a difference and it was wrong.
> 
> I know that exactly the value 0.1 is one that can not be represented
> using
> binary rep. Maybe that's it, maybe not. Just wanted to let you know.
> 
> With kind regards
> 
> Manuel
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

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


Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-04 Thread Duncan Murdoch

On 04/08/2009 1:41 PM, Richardson, Ash wrote:

Dear Ravi,

Here's an idea:  if R uses the C++ library complex.h, then the problem may lie 
in the C++ library.
(Or how the C++ library is being called: perhaps it's defaulting to single 
precision floating point).

I recently wrote an eigen-solver for a complex matrix using explicit formula;
using the C++ library I got residuals of 10^-5. 

Using a complex number class I wrote myself using the polar representation, 
the same program got residuals of 10^-15.


The complex functions in standard C don't seem to have the same problem.  
I think there is something wrong with the C++ implementation of complex numbers.

I think matlab uses the standard C implementation of complex numbers, so it 
doesn't suffer from this problem.


R uses the C runtime, not C++.  But the cpow function was not very good. 
 Blame Microsoft for that on Windows, some other scapegoat on whatever 
other platform you use.


Martin M. has now committed some changes to R-devel that give these 
results on Windows:


> #-- Classical Rosenbrock function in n variables
> rosen <- function(x) {
+ n <- length(x)
+ x1 <- x[2:n]
+ x2 <- x[1:(n-1)]
+ sum(100*(x1-x2^2)^2 + (1-x2)^2)
+ }
>
>
> x0 <- c(0.0094, 0.7146, 0.2179, 0.6883, 0.5757, 0.9549, 0.7136, 
0.0849, 0.4147, 0.4540)

> h <- c(1.e-15*1i, 0, 0, 0, 0, 0, 0, 0, 0, 0)
> xh <- x0 + h
>
> rx <- rosen(xh)
> Re(rx)
[1] 190.3080
> Im (rx)
[1] -4.667764e-15

These seem to agree with the desired numbers.

Duncan Murdoch




Best regards,

~ Ash

__

Ash Richardson, BSc

Physical Scientist / Spécialiste des science physiques
Natural Resources Canada / Ressources naturelles Canada
Canadian Forest Service / Service canadien des forêts
Pacific Forestry Centre / Centre de foresterie du Pacifique
506 W. Burnside Road / 506 rue Burnside Ouest
Victoria, BC  V8Z 1M5 / Victoria, C-B V8Z 1M5

Tel: (250) 363-6018   Facs: (250) 363-0775
mailto:ashri...@nrcan.gc.ca
___



-Original Message-
From: r-devel-boun...@r-project.org on behalf of Ravi Varadhan
Sent: Tue 8/4/2009 7:59 AM
To: 'Martin Becker'
Cc: hwborch...@googlemail.com; r-de...@stat.math.ethz.ch
Subject: Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)


Please forgive me for my lack of understanding of IEEE floating-point
arithmetic.  I have a hard time undertsanding why "this is not a problem of
R itself", when "ALL" the other well known computing environments including
Matlab, Octave, S+, and Scilab provide accurate results.  My concern is not
really about the "overall" accuracy of R, but just about the complex
arithmetic.  Is there something idiosyncratic about the complex arithmetic?


I am really hoping that some one from the R core would speak up and address
this issue.  It would be a loss to the R users if this fascinating idea of
"complex-step derivative" could not be implemented in R.

Thanks,
Ravi. 



---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 


Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml







-Original Message-
From: Martin Becker [mailto:martin.bec...@mx.uni-saarland.de] 
Sent: Tuesday, August 04, 2009 7:34 AM

To: Ravi Varadhan
Cc: r-de...@stat.math.ethz.ch; hwborch...@googlemail.com
Subject: Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

Dear Ravi,

I suspect that, in general, you may be facing the limitations of machine
accuracy (more precisely, IEEE 754 arithmetics on [64-bit] doubles) in your
application. This is not a problem of R itself, but rather a problem of
standard arithmetics provided by underlying C compilers/CPUs.
In fact, every operation in IEEE arithmetics (so, this is not really a
problem only for complex numbers) may suffer from inexactness, a
particularly difficult one is addition/subtraction. Consider the following
example for real numbers (I know, it is not a very good one...):
The two functions

badfn <- function(x) 1-(1+x)*(1-x)
goodfn <- function(x) x^2

both calculate x^2 (theoretically, given perfect arithmetic). So, as you
want to allow the user to 'specify the mathematical function ... in "any"
form the user chooses', both functions should be ok.
But, unfortunately:

 > badfn(1e-8)
[1] 2.220446049250313e-16
 > goodfn(1e-8)
[1] 1e-16

I don't know what happens in matlab/octave/scilab for this example. They may
do better, but probably at some cost (dropping IEEE arithmetic/do "clever"
calculations should result in massive speed penalties, try 
evaluating   hypergeom([1,-99.9],[-49.9-24.9*I],(1+1.71*I)/2);   in 
Maple...).

Now, you 

[Rd] Alt-F4 leaves RGUI console in wait state when closing some dialog boxes (PR#13870)

2009-08-04 Thread richcalaway
Full_Name: Rich Calaway
Version: R 2.7.2; R 2.10.0 r48968 2009-07-21
OS: Windows Vista Ultimate SP1, Windows XP SP3
Submission from: (NULL) (65.47.30.18)


Various dialog boxes have different responses to Alt-F4; all of those launched
from the File menu behave correctly--the dialog box closes and the R Console
window responds to input. 

In the Edit menu, when you select Data editor..., and use Alt+F4 to try to close
the dialog box that prompts for the name of a matrix or data frame, the dialog
box closes, the R Console seems unresponsive, but the cursor does not change,
and all menu items are available. If you do the following, however, you see that
all is not well. Choose New script from the File menu, then enter the following
lines:

search()
ls()

If you then try to Run all from the Edit menu, nothing appears to happen. Now
choose Data editor... again, and type in a name, such as state.x77. The data
editor opens, and all of the commands you tried to run in the interim now go
through the R Console. When you exit the data editor, it opens again with the
same data set. When you exit a second time, you should be back to normal.

In the Packages menu, the Load package..., Set CRAN mirror..., Select
Repositories..., and Install packages... dialog boxes all behave the same
way--if you press Alt+F4 after opening these dialog boxes, the dialog box
closes, the cursor becomes a wait cursor while over the R Console, and clicking
Stop returns you to the R prompt.

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


[Rd] Sweave errors during package building

2009-08-04 Thread Claudia Beleites
Dear all,

I just spent quite a while fixing a weird error in my vignettes while doing
R CMD build and R CMD check
R CMD Sweave ran fine, though.

The cause turned out to be:

1. I have a data set flu,
2. and  a corresponding vignette explaining things one can do with that 
object. This vignette creates another object flu (which masks the packages 
one). 
3. Now when the next vignette is processed, this object created by the first 
vignette still exists, and still masks the packaged data set.

I was assuming that the building and checking processes are like R CMD Sweave, 
but this is not the case: they are like Sweave inside R, which will also 
change objects in the workspace (as I now know, see the example).

Maybe I didn't enough RTFM, but I was completely unaware of that before.

Would it be a good idea to have a few words about this in the FAQ and in the 
help page? 

Claudia


file testsweave.Rnw:
<>=
a <- 3
b <- 1
@ 

now in R:
> a <- 4
> a
[1] 4
> b
Error: object 'b' not found
> Sweave ("testsweave.Rnw")
Writing to file testsweave.tex
Processing code chunks ...
 1 : echo term verbatim (label=test)

You can now run LaTeX on 'testsweave.tex'
> a
[1] 3
> b
[1] 1
> 



-- 
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali 
Università degli Studi di Trieste 
Via Alfonso Valerio 6/a 
I-34127 Trieste

phone: +39 0 40 5 58-37 68 
email: cbelei...@units.it

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


Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-04 Thread Richardson, Ash
Dear Ravi,

Here's an idea:  if R uses the C++ library complex.h, then the problem may lie 
in the C++ library.
(Or how the C++ library is being called: perhaps it's defaulting to single 
precision floating point).

I recently wrote an eigen-solver for a complex matrix using explicit formula;
using the C++ library I got residuals of 10^-5. 

Using a complex number class I wrote myself using the polar representation, 
the same program got residuals of 10^-15.

The complex functions in standard C don't seem to have the same problem.  
I think there is something wrong with the C++ implementation of complex numbers.
I think matlab uses the standard C implementation of complex numbers, so it 
doesn't suffer from this problem.

Best regards,

~ Ash

__

Ash Richardson, BSc

Physical Scientist / Spécialiste des science physiques
Natural Resources Canada / Ressources naturelles Canada
Canadian Forest Service / Service canadien des forêts
Pacific Forestry Centre / Centre de foresterie du Pacifique
506 W. Burnside Road / 506 rue Burnside Ouest
Victoria, BC  V8Z 1M5 / Victoria, C-B V8Z 1M5

Tel: (250) 363-6018   Facs: (250) 363-0775
mailto:ashri...@nrcan.gc.ca
___



-Original Message-
From: r-devel-boun...@r-project.org on behalf of Ravi Varadhan
Sent: Tue 8/4/2009 7:59 AM
To: 'Martin Becker'
Cc: hwborch...@googlemail.com; r-de...@stat.math.ethz.ch
Subject: Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)


Please forgive me for my lack of understanding of IEEE floating-point
arithmetic.  I have a hard time undertsanding why "this is not a problem of
R itself", when "ALL" the other well known computing environments including
Matlab, Octave, S+, and Scilab provide accurate results.  My concern is not
really about the "overall" accuracy of R, but just about the complex
arithmetic.  Is there something idiosyncratic about the complex arithmetic?


I am really hoping that some one from the R core would speak up and address
this issue.  It would be a loss to the R users if this fascinating idea of
"complex-step derivative" could not be implemented in R.

Thanks,
Ravi. 


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml







-Original Message-
From: Martin Becker [mailto:martin.bec...@mx.uni-saarland.de] 
Sent: Tuesday, August 04, 2009 7:34 AM
To: Ravi Varadhan
Cc: r-de...@stat.math.ethz.ch; hwborch...@googlemail.com
Subject: Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

Dear Ravi,

I suspect that, in general, you may be facing the limitations of machine
accuracy (more precisely, IEEE 754 arithmetics on [64-bit] doubles) in your
application. This is not a problem of R itself, but rather a problem of
standard arithmetics provided by underlying C compilers/CPUs.
In fact, every operation in IEEE arithmetics (so, this is not really a
problem only for complex numbers) may suffer from inexactness, a
particularly difficult one is addition/subtraction. Consider the following
example for real numbers (I know, it is not a very good one...):
The two functions

badfn <- function(x) 1-(1+x)*(1-x)
goodfn <- function(x) x^2

both calculate x^2 (theoretically, given perfect arithmetic). So, as you
want to allow the user to 'specify the mathematical function ... in "any"
form the user chooses', both functions should be ok.
But, unfortunately:

 > badfn(1e-8)
[1] 2.220446049250313e-16
 > goodfn(1e-8)
[1] 1e-16

I don't know what happens in matlab/octave/scilab for this example. They may
do better, but probably at some cost (dropping IEEE arithmetic/do "clever"
calculations should result in massive speed penalties, try 
evaluating   hypergeom([1,-99.9],[-49.9-24.9*I],(1+1.71*I)/2);   in 
Maple...).
Now, you have some options:

- assume, that the user is aware of the numerical inexactness of ieee
arithmetics and that he is able to supply some "robust" version of the
mathematical function.
- use some other software (eg., matlab) for the critical calculations (there
is a R <-> Matlab interface, see package R.matlab on CRAN), if you are sure,
that this helps.
- implement/use multiple precision arithmetics within R (Martin Maechler's
Rmpfr package may be very useful: 
http://r-forge.r-project.org/projects/rmpfr/ , but this will slow down
calculations considerably)

All in all, I think it is unfair just to blame R here. Of course, it would
be great if there was a simple trigger to turn on multiple precision
arithmetics in R. Packages such as Rmpfr may provide a good step in th

Re: [Rd] Accuracy (PR#13867)

2009-08-04 Thread Petr Savicky
On Tue, Aug 04, 2009 at 04:25:09PM +0200, lueth...@student.ethz.ch wrote:
> Hi
> 
> I created the following vectors:
> 
> p_1=c(0.2,0.2,0.2,0.2,0.1,0.25,0.4,0.1,0.25,0.4,0.1,0.25,0.4,0.1,0.25,0.4,0.2,0.5,0.8,0.2,0.5,0.8,0.2,0.5,0.8,0.2,0.5,0.8)
> p_2=c(0,0,0,0,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.4,0.25,0.1,0.4,0.25,0.1,0.4,0.25,0.1,0.4,0.25,0.1)
> 
> As these are probabilities, I calculated the remainder as
> 
> p_3=1-p_1-p_2
> 
> There the values which ought to be 0.1 were lateron not recognised by 
> p_3==0.1,
> but only if I used p_3 <= 0.1.
> 
> The full calculation is actually bigger but the core issue remains: I used
> values input by hand, built a difference and it was wrong.
> 
> I know that exactly the value 0.1 is one that can not be represented using
> binary rep. Maybe that's it, maybe not.

Yes, this is the problem. In this case, one can obtain a correct
result using round()

  p1 <- c(0.2,0.2,0.2,0.2,0.1,0.25,0.4,0.1,0.25,0.4,0.1,0.25,0.4,0.1,
  0.25,0.4,0.2,0.5,0.8,0.2,0.5,0.8,0.2,0.5,0.8,0.2,0.5,0.8)
  p2 <- c(0,0,0,0,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.4,
  0.25,0.1,0.4,0.25,0.1,0.4,0.25,0.1,0.4,0.25,0.1)
  p3 <- 1 - p1 - p2
  round(p3, 2) == 0.1
  #  [1] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE
  # [13]  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE
  # [25]  TRUE FALSE FALSE  TRUE

Petr.

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


Re: [Rd] can a key of a list be a variable

2009-08-04 Thread Tony Plate

Patterns like these can help to do what you want:

> lapply(setNames(1:3, paste("step", 1:3, sep="")), function(i) seq(i))
$step1
[1] 1

$step2
[1] 1 2

$step3
[1] 1 2 3

> setNames(list("the result"), paste("a", "name"))
$`a name`
[1] "the result"

>

-- Tony Plate

Bilel MASMOUDI wrote:

Hi,

I search a solution to record data in dynamic structures in R.
I have an algorithm that will be executed each step and whose output is an
array of doubles with unknown size.

The solution I found is to use lists
1) I initialise my list
 l <- list()
2) and at a step numbered i I conacatain the new tab to the list
vect <- algorithm()
l <<--c( l , list(stepi=vect))

The problem is that the key "stepi" is here a constant, I'd like to use a
variable like this
x = paste("step",index,sep="") where index is the last index (i)
l <<--c( l , list(x=vect)) --> this doesn't function, the key is named "x"
not "stepi"
If I write l <<--c( l , list(paste("step",index,sep="") =vect)), I receive
an error

Many thanks for your help



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


[Rd] Accuracy (PR#13867)

2009-08-04 Thread luethman
Full_Name: Manuel Luethi
Version: 2.9.1
OS: Windows XP
Submission from: (NULL) (129.132.128.136)


Hi

I created the following vectors:

p_1=c(0.2,0.2,0.2,0.2,0.1,0.25,0.4,0.1,0.25,0.4,0.1,0.25,0.4,0.1,0.25,0.4,0.2,0.5,0.8,0.2,0.5,0.8,0.2,0.5,0.8,0.2,0.5,0.8)
p_2=c(0,0,0,0,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.4,0.25,0.1,0.4,0.25,0.1,0.4,0.25,0.1,0.4,0.25,0.1)

As these are probabilities, I calculated the remainder as

p_3=1-p_1-p_2

There the values which ought to be 0.1 were lateron not recognised by p_3==0.1,
but only if I used p_3 <= 0.1.

The full calculation is actually bigger but the core issue remains: I used
values input by hand, built a difference and it was wrong.

I know that exactly the value 0.1 is one that can not be represented using
binary rep. Maybe that's it, maybe not. Just wanted to let you know.

With kind regards

Manuel

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


Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-04 Thread Ravi Varadhan

Please forgive me for my lack of understanding of IEEE floating-point
arithmetic.  I have a hard time undertsanding why "this is not a problem of
R itself", when "ALL" the other well known computing environments including
Matlab, Octave, S+, and Scilab provide accurate results.  My concern is not
really about the "overall" accuracy of R, but just about the complex
arithmetic.  Is there something idiosyncratic about the complex arithmetic?


I am really hoping that some one from the R core would speak up and address
this issue.  It would be a loss to the R users if this fascinating idea of
"complex-step derivative" could not be implemented in R.

Thanks,
Ravi. 


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml

 





-Original Message-
From: Martin Becker [mailto:martin.bec...@mx.uni-saarland.de] 
Sent: Tuesday, August 04, 2009 7:34 AM
To: Ravi Varadhan
Cc: r-de...@stat.math.ethz.ch; hwborch...@googlemail.com
Subject: Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

Dear Ravi,

I suspect that, in general, you may be facing the limitations of machine
accuracy (more precisely, IEEE 754 arithmetics on [64-bit] doubles) in your
application. This is not a problem of R itself, but rather a problem of
standard arithmetics provided by underlying C compilers/CPUs.
In fact, every operation in IEEE arithmetics (so, this is not really a
problem only for complex numbers) may suffer from inexactness, a
particularly difficult one is addition/subtraction. Consider the following
example for real numbers (I know, it is not a very good one...):
The two functions

badfn <- function(x) 1-(1+x)*(1-x)
goodfn <- function(x) x^2

both calculate x^2 (theoretically, given perfect arithmetic). So, as you
want to allow the user to 'specify the mathematical function ... in "any"
form the user chooses', both functions should be ok.
But, unfortunately:

 > badfn(1e-8)
[1] 2.220446049250313e-16
 > goodfn(1e-8)
[1] 1e-16

I don't know what happens in matlab/octave/scilab for this example. They may
do better, but probably at some cost (dropping IEEE arithmetic/do "clever"
calculations should result in massive speed penalties, try 
evaluating   hypergeom([1,-99.9],[-49.9-24.9*I],(1+1.71*I)/2);   in 
Maple...).
Now, you have some options:

- assume, that the user is aware of the numerical inexactness of ieee
arithmetics and that he is able to supply some "robust" version of the
mathematical function.
- use some other software (eg., matlab) for the critical calculations (there
is a R <-> Matlab interface, see package R.matlab on CRAN), if you are sure,
that this helps.
- implement/use multiple precision arithmetics within R (Martin Maechler's
Rmpfr package may be very useful: 
http://r-forge.r-project.org/projects/rmpfr/ , but this will slow down
calculations considerably)

All in all, I think it is unfair just to blame R here. Of course, it would
be great if there was a simple trigger to turn on multiple precision
arithmetics in R. Packages such as Rmpfr may provide a good step in this
direction, since operator overloading via S4 classes allows for easy code
adaption. But Rmpfr is still declared "beta", and it relies on some external
library, which could be problematic on Windows systems. Maybe someone else
has other/better suggestions, but I do not think that there is an easy
solution for the "general" problem.

Best wishes,

  Martin
 

Ravi Varadhan wrote:
> Dear Martin,
>
> Thank you for this useful trick.  However, we are interested in a
"general"
> approach for exact derivative computation.  This approach should allow 
> the user to specify the mathematical function that needs to be 
> differentiated in "any" form that the user chooses.  So, your trick 
> will be difficult to implement there.  Furthermore, do we know for 
> sure that `exponentiation' is the only operation that results in 
> inaccuracy?  Are there other operations that also yield inaccurate results
for complex arithmetic?
>
> Hans Borchers also checked the computations with other free numerical 
> software, such as Octave, Scilab, Euler, and they all return exactly 
> the same results as Matlab.  It would be a shame if R could not do the
same.
>
> It would be great if the R core could address the "fundamental" issue. 
>
> Thank you.
>
> Best regards,
> Ravi.
>
> --
> --
> ---
>
> Ravi Varadhan, Ph.D.
>
> Assistant Professor, The Center on Aging and Health
>
> Division of Geriatric Medicine and Gerontology
>
> Johns Hopkins University
>
> Ph: (410) 50

Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-04 Thread Ravi Varadhan
Dear Martin,

Thank you for this useful trick.  However, we are interested in a "general"
approach for exact derivative computation.  This approach should allow the
user to specify the mathematical function that needs to be differentiated in
"any" form that the user chooses.  So, your trick will be difficult to
implement there.  Furthermore, do we know for sure that `exponentiation' is
the only operation that results in inaccuracy?  Are there other operations
that also yield inaccurate results for complex arithmetic?  

Hans Borchers also checked the computations with other free numerical
software, such as Octave, Scilab, Euler, and they all return exactly the
same results as Matlab.  It would be a shame if R could not do the same.  

It would be great if the R core could address the "fundamental" issue. 

Thank you.

Best regards,
Ravi.


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml

 





-Original Message-
From: Martin Becker [mailto:martin.bec...@mx.uni-saarland.de] 
Sent: Monday, August 03, 2009 5:50 AM
To: Ravi Varadhan
Cc: r-de...@stat.math.ethz.ch; hwborch...@googlemail.com
Subject: Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

Dear Ravi,

the inaccuracy seems to creep in when powers are calculated. Apparently,
some quite general function is called to calculate the squares, and one can
avoid the error by reformulating the example as follows:

rosen <- function(x) {
  n <- length(x)
  x1 <- x[2:n]
  x2 <- x[1:(n-1)]
  sum(100*(x1-x2*x2)*(x1-x2*x2) + (1-x2)*(1-x2)) }

x0 <- c(0.0094, 0.7146, 0.2179, 0.6883, 0.5757, 0.9549, 0.7136, 0.0849,
0.4147, 0.4540) h <- c(1.e-15*1i, 0, 0, 0, 0, 0, 0, 0, 0, 0) xh <- x0 + h

rx <- rosen(xh)
Re(rx)
Im (rx)


I don't know which arithmetics are involved in the application you
mentioned, but writing some auxiliary function for the calculation of x^n
when x is complex and n is (a not too large) integer may solve some of the
numerical issues. A simple version is:

powN <- function(x,n) sapply(x,function(x) prod(rep(x,n)))

The corresponding summation in 'rosen' would then read:

sum(100*powN(x1-powN(x2,2),2) + powN(1-x2,2))


HTH,

  Martin


Ravi Varadhan wrote:
> Dear All,
>
> Hans Borchers and I have been trying to compute "exact" derivatives in R
using the idea of complex-step derivatives that Hans has proposed.  This is
a really, really cool idea.  It gives "exact" derivatives with only a
minimal effort (same as that involved in computing first-order
forward-difference derivative).  
>
> Unfortunately, we cannot implement this in R as the "complex arithmetic"
in R appears to be inaccurate.
>
> Here is an example:
>
> #-- Classical Rosenbrock function in n variables rosen <- function(x) 
> { n <- length(x)
> x1 <- x[2:n]
> x2 <- x[1:(n-1)]
> sum(100*(x1-x2^2)^2 + (1-x2)^2)
> }
>
>
> x0 <- c(0.0094, 0.7146, 0.2179, 0.6883, 0.5757, 0.9549, 0.7136, 
> 0.0849, 0.4147, 0.4540) h <- c(1.e-15*1i, 0, 0, 0, 0, 0, 0, 0, 0, 0) 
> xh <- x0 + h
>
> rx <- rosen(xh)
> Re(rx)
> Im (rx)
>
> #  rx = 190.3079796814885 - 12.13915588266717e-15 i  # incorrect 
> imaginary part in R
>
> However, the imaginary part of the above answer is inaccurate.  The
correct imaginary part (from Matlab) is:
>
> 190.3079796814886 - 4.6677637664e-15 i  # correct imaginary part 
> from Matlab
>
> This inaccuracy is serious enough to affect the acuracy of the compex-step
gradient drastically.
>
> Hans and I were wondering if there is a way to obtain accurate "small"
imaginary part for complex arithmetic.  
>
> I am using Windows XP operating system.
>
> Thanks for taking a look at this.
>
> Best regards,
> Ravi.
>
>
> 
>
> Ravi Varadhan, Ph.D.
> Assistant Professor,
> Division of Geriatric Medicine and Gerontology School of Medicine 
> Johns Hopkins University
>
> Ph. (410) 502-2619
> email: rvarad...@jhmi.edu
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>   


--
Dr. Martin Becker
Statistics and Econometrics
Saarland University
Campus C3 1, Room 206
66123 Saarbruecken
Germany

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


Re: [Rd] can a key of a list be a variable

2009-08-04 Thread Bilel MASMOUDI
Hi,

I found a solution: creating lists without using keys
l<<-c(l,list(x))

Many thanks,


2009/8/4 Bilel MASMOUDI 

> Hi,
>
> I search a solution to record data in dynamic structures in R.
> I have an algorithm that will be executed each step and whose output is an
> array of doubles with unknown size.
>
> The solution I found is to use lists
> 1) I initialise my list
>  l <- list()
> 2) and at a step numbered i I conacatain the new tab to the list
> vect <- algorithm()
> l <<--c( l , list(stepi=vect))
>
> The problem is that the key "stepi" is here a constant, I'd like to use a
> variable like this
> x = paste("step",index,sep="") where index is the last index (i)
> l <<--c( l , list(x=vect)) --> this doesn't function, the key is named "x"
> not "stepi"
> If I write l <<--c( l , list(paste("step",index,sep="") =vect)), I receive
> an error
>
> Many thanks for your help
> --
> Bilel
>
> --
> Bilel
>



-- 
Bilel

[[alternative HTML version deleted]]

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


[Rd] can a key of a list be a variable

2009-08-04 Thread Bilel MASMOUDI
Hi,

I search a solution to record data in dynamic structures in R.
I have an algorithm that will be executed each step and whose output is an
array of doubles with unknown size.

The solution I found is to use lists
1) I initialise my list
 l <- list()
2) and at a step numbered i I conacatain the new tab to the list
vect <- algorithm()
l <<--c( l , list(stepi=vect))

The problem is that the key "stepi" is here a constant, I'd like to use a
variable like this
x = paste("step",index,sep="") where index is the last index (i)
l <<--c( l , list(x=vect)) --> this doesn't function, the key is named "x"
not "stepi"
If I write l <<--c( l , list(paste("step",index,sep="") =vect)), I receive
an error

Many thanks for your help
-- 
Bilel

-- 
Bilel

[[alternative HTML version deleted]]

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


[Rd] would like to subscribe...

2009-08-04 Thread Hyo Karen Lee
totem...@gmail.com

Thanks.

[[alternative HTML version deleted]]

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


Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-04 Thread Martin Maechler
> "MM" == Martin Maechler 
> on Mon, 3 Aug 2009 19:30:24 +0200 writes:

> "HWB" == Hans W Borchers 
> on Mon, 3 Aug 2009 13:15:11 + (UTC) writes:

  >>> 
  HWB> Thanks for pointing out the weak point in this
  HWB> computation. I tried out your suggestions and they both
  HWB> deliver the correct and accurate result.

  HWB> But as a general solution this approach is not
  HWB> feasible. We want to provide "complex-step derivatives"
  HWB> as a new method for computing exact gradients, for
  HWB> example in 'numDeriv::grad' as

  HWB> grad(fun, x, method="complex-step")

  HWB> and we can not reasonably assume that a user prepares
  HWB> his function specially for calling this method.

  HWB> I tried out other numerical math software besides
  HWB> Matlab, that is Octave, Scilab, Euler and others, and
  HWB> they all return the same correct value up to 15
  HWB> digits. Should we not expect that R is capable of doing
  HWB> the same?

MM> R's  "a ^ b"  on non-Windows typically uses the C library's
MM> 'cpow()'  when that is provided  (HAVE_C99_COMPLEX).

MM> Indeed, this seems to use the "general" complex power function
MM> which loses a few bits -- unavoidably.
MM> Our Windows-version of complex  a ^ b  does so as well.

MM> Here's an R version of what (I believe) once was the C library
MM> cpow(); at least I confirm that it has the same slight
MM> inaccuracy [if you are as this very border line case with '1e-15';
MM> use  1e-12  and you have no problems !! ]

MM> Cpow <- function(a,b)
MM> {
MM> ## Purpose: a ^ b  in complex
MM> ## Find bug in  complex_pow()
MM> ## 
-
MM> ## Author: Martin Maechler, Date: 15 Jan 2000, 21:33

MM> a <- as.complex(a)
MM> b <- as.complex(b)

MM> hypot <- function(x,y)Mod(x + 1i*y)

MM> logr <- log(hypot(Re(a), Im(a)) );
MM> logi <- atan2(Im(a), Re(a));
MM> x <- exp( logr * Re(b) - logi * Im(b) );
MM> y <- logr * Im(b) + logi * Re(b);

MM> x * complex(re= cos(y), im= sin(y))
MM> }

MM> 

MM> So, yes we could check for the special case of  "^2" and use
MM> multiplication and then for   " ^ n " and ... ...
MM> and only otherwise call cpow(x,y) {or our own C-version of
MM> that}.

MM> I'm looking into implenting that now.
MM> Expect to hear more about it within 24 hours.

I have now committed a change to R-devel (not sure if to be
back-ported to R-patched)
which uses  ~ log2(n) multiplications  for  z^n  when
n is integer (and  |n| <= 2^16 ; that cut-off being somewhat arbitrary).

Along the same line, I've looked what we do for  x^y  when x,y
are double. Till now, we had only special cased the cases
y == 0 (, 1), 2; and after some simple tests, I've decided to
use the log(n) #{multiplications} algorithm, whenever |n| <= 256.

Thanks also to Tom Short for investigating what other free
packages use.

Martin Maechler, ETH Zurich




HWB> Martin Becker  mx.uni-saarland.de>
HWB> writes:

>>> 
>>> Dear Ravi,
>>> 
>>> the inaccuracy seems to creep in when powers are
>>> calculated. Apparently, some quite general function is
>>> called to calculate the squares, and one can avoid the
>>> error by reformulating the example as follows:
>>> 
>>> rosen <- function(x) { n <- length(x) x1 <- x[2:n] x2 <-
>>> x[1:(n-1)] sum(100*(x1-x2*x2)*(x1-x2*x2) + (1-x2)*(1-x2))
>>> }
>>> 
>>> x0 <- c(0.0094, 0.7146, 0.2179, 0.6883, 0.5757, 0.9549,
>>> 0.7136, 0.0849,
HWB> 0.4147, 0.4540)
>>> h <- c(1.e-15*1i, 0, 0, 0, 0, 0, 0, 0, 0, 0) xh <- x0 + h
>>> 
>>> rx <- rosen(xh) Re(rx) Im (rx)
>>> 
>>> I don't know which arithmetics are involved in the
>>> application you mentioned, but writing some auxiliary
>>> function for the calculation of x^n when x is complex and
>>> n is (a not too large) integer may solve some of the
>>> numerical issues. A simple version is:
>>> 
>>> powN <- function(x,n) sapply(x,function(x)
>>> prod(rep(x,n)))
>>> 
>>> The corresponding summation in 'rosen' would then read:
>>> 
>>> sum(100*powN(x1-powN(x2,2),2) + powN(1-x2,2))
>>> 
>>> HTH,
>>> 
>>> Martin
>>> 

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

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

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


Re: [Rd] Wishlist: Navigate to "Index" page of help when no topic (PR#13868)

2009-08-04 Thread murdoch
On 7/28/2009 6:30 PM, smckin...@bccrc.ca wrote:
> Hi all,
> 
> When I install a new package, and don't yet know any function names,
> I have to play the "poor man's game" to get to the standard
> help system "Index" page for the package:

You could complain to the package author or maintainer, who should have 
created a help alias with the package name so that ?survival would give 
you something useful.  But I would guess R 2.10.x or 2.11.x will do that 
automatically.

Duncan Murdoch

> Poor Man's Game -=20
>   Load new package;=20
>   issue search() command;
>   find position (say N) of loaded package;=20
>   issue objects(pos =3D N) command;
>   get name of a random function (san newFunction);=20
>   issue ?newFunction command;
>   scroll to bottom of page;=20
>   click on the "Index" hyperlink
> 
> There are other variations, but they all involve this=20
> long march to the Index page.
> 
> 
> What I'd like to be able to do is enter the command
> 
>> help(package =3D "survival")
> 
> or
> 
>> ?survival::
> 
> and get the usual hyperlinked help page displayed (the "00Index" page)
> instead of the static "text only" display or an error message
> 
> (for example, on Windows, this equates to invoking
> "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
> on Apple Mac,
> "/Library/Frameworks/R.framework/Resources/library/survival/html/00Index.ht=
> ml"
> etc.)
> 
> 
> Details:
> ---
> 
> The help() function returns an object of
> class "help_files_with_topic".
> The object consists of a character vector
> with several attributes.
> 
> PC:  Windows XP
> 
>> library("survival")
>> foo <- help("aareg", package =3D "survival")
>> class(foo)
> [1] "help_files_with_topic"
>> foo[1]
> [1] "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/aareg"
>> attributes(foo)
> $call
> help(topic =3D "aareg", package =3D "survival")
> 
> $pager
> [1] "internal"
> 
> $topic
> [1] "aareg"
> 
> $tried_all_packages
> [1] FALSE
> 
> $type
> [1] "chm"
> 
> $class
> [1] "help_files_with_topic"
> 
>> bar <- help("", package =3D "survival")
>> class(bar)
> [1] "help_files_with_topic"
>> bar[1]
> [1] NA
>> attributes(bar)
> $call
> help(topic =3D "", package =3D "survival")
> 
> $pager
> [1] "internal"
> 
> $topic
> [1] ""
> 
> $tried_all_packages
> [1] FALSE
> 
> $type
> [1] "chm"
> 
> $class
> [1] "help_files_with_topic"
> 
> If I alter the character vector to
> point to "00Index"
> 
>> bar[1] <- "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
>> bar
> 
> I see exactly what I've been attempting to achieve.
> 
> 
> Mac OS X:
> 
>> foo <- help("aareg", package =3D "survival")
>> foo[1]
> [1] "/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.=
> html"
>> attributes(foo)
> $call
> help(topic =3D "aareg", package =3D "survival")
> 
> $pager
> [1] "/Library/Frameworks/R.framework/Resources/bin/pager"
> 
> $topic
> [1] "aareg"
> 
> $tried_all_packages
> [1] FALSE
> 
> $type
> [1] "html"
> 
> $class
> [1] "help_files_with_topic"
> 
>> bar <- help("", package =3D "survival")
>> bar[1]
> [1] NA
>> bar[1] <- "/Library/Frameworks/R.framework/Resources/library/survival/htm=
> l/00Index.html"
>> bar
> 
> Again I see exactly what I've been after.
> 
> Running R in Emacs on Mac OS X:
> 
>> foo <- help(topic =3D "aareg", package =3D "survival")
>> foo[1]
> [1] "/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.=
> html"
>> attributes(foo)
> $call
> help(topic =3D "aareg", package =3D "survival")
> 
> $pager
> [1] "/Library/Frameworks/R.framework/Resources/bin/pager"
> 
> $topic
> [1] "aareg"
> 
> $tried_all_packages
> [1] FALSE
> 
> $type
> [1] "html"
> 
> $class
> [1] "help_files_with_topic"
> 
>> bar <- help(topic =3D "", package =3D "survival")
>> bar[1]
> [1] NA
>> bar[1] <- "/Library/Frameworks/R.framework/Resources/library/survival/htm=
> l/00Index.html"
>> bar
> Help for '' is shown in browser /usr/bin/open ...
> Use
> help("", htmlhelp =3D FALSE)
> or
> options(htmlhelp =3D FALSE)
> to revert.
>>
> 
> Again, what I've been trying to achieve.
> 
> When a user loads a new library and doesn't yet know any function names,
> I think
>> help(package =3D "newLibrary")
> or
>> ?newLibrary::
> 
> should perform the above action whenever possible instead of
> producing static help or an error message.
> 
> The "00Index" 'object' should be available for such use
> whenever it exists. =20
> 
> I have not yet worked out all the coding details to make this happen,
> but before I do, am I missing some key point?  Any reasons why this
> would be a Bad Idea?
> 
> 
> 
> Steven McKinney, Ph.D.
> 
> Statistician
> Molecular Oncology and Breast Cancer Program
> British Columbia Cancer Research Centre
> 
> email: smckinney +at+ bccrc +dot+ ca
> 
> tel: 604-675-8000 x7561
> 
> BCCRC
> Molecular Oncology
> 675 West 10th Ave, Floor 4
> Vancouver B.C.
> V5Z 1L3
> Canada
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/

Re: [Rd] Wishlist: Navigate to "Index" page of help when no topic specified (PR#13860)

2009-08-04 Thread Duncan Murdoch

On 7/28/2009 6:30 PM, smckin...@bccrc.ca wrote:

Hi all,

When I install a new package, and don't yet know any function names,
I have to play the "poor man's game" to get to the standard
help system "Index" page for the package:


You could complain to the package author or maintainer, who should have 
created a help alias with the package name so that ?survival would give 
you something useful.  But I would guess R 2.10.x or 2.11.x will do that 
automatically.


Duncan Murdoch


Poor Man's Game -=20
  Load new package;=20
  issue search() command;
  find position (say N) of loaded package;=20
  issue objects(pos =3D N) command;
  get name of a random function (san newFunction);=20
  issue ?newFunction command;
  scroll to bottom of page;=20
  click on the "Index" hyperlink

There are other variations, but they all involve this=20
long march to the Index page.


What I'd like to be able to do is enter the command


help(package =3D "survival")


or


?survival::


and get the usual hyperlinked help page displayed (the "00Index" page)
instead of the static "text only" display or an error message

(for example, on Windows, this equates to invoking
"C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
on Apple Mac,
"/Library/Frameworks/R.framework/Resources/library/survival/html/00Index.ht=
ml"
etc.)


Details:
---

The help() function returns an object of
class "help_files_with_topic".
The object consists of a character vector
with several attributes.

PC:  Windows XP


library("survival")
foo <- help("aareg", package =3D "survival")
class(foo)

[1] "help_files_with_topic"

foo[1]

[1] "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/aareg"

attributes(foo)

$call
help(topic =3D "aareg", package =3D "survival")

$pager
[1] "internal"

$topic
[1] "aareg"

$tried_all_packages
[1] FALSE

$type
[1] "chm"

$class
[1] "help_files_with_topic"


bar <- help("", package =3D "survival")
class(bar)

[1] "help_files_with_topic"

bar[1]

[1] NA

attributes(bar)

$call
help(topic =3D "", package =3D "survival")

$pager
[1] "internal"

$topic
[1] ""

$tried_all_packages
[1] FALSE

$type
[1] "chm"

$class
[1] "help_files_with_topic"

If I alter the character vector to
point to "00Index"


bar[1] <- "C:/PROGRA~1/R/R-29~1.1/library/survival/chm/00Index"
bar


I see exactly what I've been attempting to achieve.


Mac OS X:


foo <- help("aareg", package =3D "survival")
foo[1]

[1] "/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.=
html"

attributes(foo)

$call
help(topic =3D "aareg", package =3D "survival")

$pager
[1] "/Library/Frameworks/R.framework/Resources/bin/pager"

$topic
[1] "aareg"

$tried_all_packages
[1] FALSE

$type
[1] "html"

$class
[1] "help_files_with_topic"


bar <- help("", package =3D "survival")
bar[1]

[1] NA

bar[1] <- "/Library/Frameworks/R.framework/Resources/library/survival/htm=

l/00Index.html"

bar


Again I see exactly what I've been after.

Running R in Emacs on Mac OS X:


foo <- help(topic =3D "aareg", package =3D "survival")
foo[1]

[1] "/Library/Frameworks/R.framework/Resources/library/survival/html/aareg.=
html"

attributes(foo)

$call
help(topic =3D "aareg", package =3D "survival")

$pager
[1] "/Library/Frameworks/R.framework/Resources/bin/pager"

$topic
[1] "aareg"

$tried_all_packages
[1] FALSE

$type
[1] "html"

$class
[1] "help_files_with_topic"


bar <- help(topic =3D "", package =3D "survival")
bar[1]

[1] NA

bar[1] <- "/Library/Frameworks/R.framework/Resources/library/survival/htm=

l/00Index.html"

bar

Help for '' is shown in browser /usr/bin/open ...
Use
help("", htmlhelp =3D FALSE)
or
options(htmlhelp =3D FALSE)
to revert.




Again, what I've been trying to achieve.

When a user loads a new library and doesn't yet know any function names,
I think

help(package =3D "newLibrary")

or

?newLibrary::


should perform the above action whenever possible instead of
producing static help or an error message.

The "00Index" 'object' should be available for such use
whenever it exists. =20

I have not yet worked out all the coding details to make this happen,
but before I do, am I missing some key point?  Any reasons why this
would be a Bad Idea?



Steven McKinney, Ph.D.

Statistician
Molecular Oncology and Breast Cancer Program
British Columbia Cancer Research Centre

email: smckinney +at+ bccrc +dot+ ca

tel: 604-675-8000 x7561

BCCRC
Molecular Oncology
675 West 10th Ave, Floor 4
Vancouver B.C.
V5Z 1L3
Canada

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


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


Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-04 Thread Hans W Borchers
> I suspect that, in general, you may be facing the limitations of machine 
> accuracy (more precisely, IEEE 754 arithmetics on [64-bit] doubles) in 

Dear Martin,

I definitely do not agree with this. Consider your own proposal of
writing the Rosenbrock function:

rosen2 <- function(x) {
n <- length(x)
x1 <- x[2:n]
x2 <- x[1:(n-1)]
sum(100*(x1-x2*x2)*(x1-x2*x2) + (1-x2)*(1-x2))
}

The complex-step derivative approximation suggests to set h <- 1.0e-20
and then to compute the expression  Im(rosen(x+hi))/h , so let's do it:

h  <- 1.0e-20
xh <- c(0.0094 + h*1i, 0.7146, 0.2179, 0.6883, 0.5757,
0.9549,0.7136, 0.0849, 0.4147, 0.4540)

Im(rosen2(xh)) / h
# [1] -4.6677637664000

which is exactly the correct derivative in the first variable, namely
d/dx1 rosen(x). To verify, you could even calculate this by hand on a
"Bierdeckel".

Now look at the former definition, say rosen1(), using '^' instead:

rosen1 <- function(x) {
n <- length(x)
x1 <- x[2:n]
x2 <- x[1:(n-1)]
sum(100*(x1-x2^2)^2 + (1-x2)^2)
}

Im(rosen1(xh)) / h
# [1] -747143.8793904837

We find that R is "running wild". And this has nothing to do with IEEE
arithmetics or machine accuracy, as we can see from the first example
where R is able to do it right.

And as I said, the second example is working correctly in free software
such as Octave which I guess does not do any "clever" calculations here.

We do _not_ ask for multiple precision arithmetics here !

Regards
Hans Werner


Martin Becker  mx.uni-saarland.de> writes:
> 
> Dear Ravi,
> 
> I suspect that, in general, you may be facing the limitations of machine 
> accuracy (more precisely, IEEE 754 arithmetics on [64-bit] doubles) in 
> your application. This is not a problem of R itself, but rather a 
> problem of standard arithmetics provided by underlying C compilers/CPUs.
> In fact, every operation in IEEE arithmetics (so, this is not really a 
> problem only for complex numbers) may suffer from inexactness, a 
> particularly difficult one is addition/subtraction. Consider the 
> following example for real numbers (I know, it is not a very good one...):
> The two functions
> 
> badfn <- function(x) 1-(1+x)*(1-x)
> goodfn <- function(x) x^2
> 
> both calculate x^2 (theoretically, given perfect arithmetic). So, as you 
> want to allow the user to 'specify the mathematical function ... in 
> "any" form the user chooses', both functions should be ok.
> But, unfortunately:
> 
>  > badfn(1e-8)
> [1] 2.220446049250313e-16
>  > goodfn(1e-8)
> [1] 1e-16
> 
> I don't know what happens in matlab/octave/scilab for this example. They 
> may do better, but probably at some cost (dropping IEEE arithmetic/do 
> "clever" calculations should result in massive speed penalties, try 
> evaluating   hypergeom([1,-99.9],[-49.9-24.9*I],(1+1.71*I)/2);   in 
> Maple...).
> Now, you have some options:
> 
> - assume, that the user is aware of the numerical inexactness of ieee 
> arithmetics and that he is able to supply some "robust" version of the 
> mathematical function.
> - use some other software (eg., matlab) for the critical calculations 
> (there is a R <-> Matlab interface, see package R.matlab on CRAN), if 
> you are sure, that this helps.
> - implement/use multiple precision arithmetics within R (Martin 
> Maechler's Rmpfr package may be very useful: 
> http://r-forge.r-project.org/projects/rmpfr/ , but this will slow down 
> calculations considerably)
> 
> All in all, I think it is unfair just to blame R here. Of course, it 
> would be great if there was a simple trigger to turn on multiple 
> precision arithmetics in R. Packages such as Rmpfr may provide a good 
> step in this direction, since operator overloading via S4 classes allows 
> for easy code adaption. But Rmpfr is still declared "beta", and it 
> relies on some external library, which could be problematic on Windows 
> systems. Maybe someone else has other/better suggestions, but I do not 
> think that there is an easy solution for the "general" problem.
> 
> Best wishes,
> 
>   Martin
>

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


Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-04 Thread Tom Short
I checked, and both octave and yorick use multiplication for z^i where
i is an integer, leading to better accuracy. Octave uses an integer
power if it's stored as a double if it's close enough to an integer.
See:

http://hg.savannah.gnu.org/hgweb/octave/file/fb22dd5d6242/src/xpow.cc
http://yorick.sourcearchive.com/documentation/2.1.01cvs20060706/ops2_8c-source.html

- Tom

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


[Rd] Inconsistencies in missing names of a list?

2009-08-04 Thread Bernd Bischl

Hi,

I would like to discuss whether the following behaviour in lists is 
indeed intended:


###
> sessionInfo()
R version 2.10.0 Under development (unstable) (2009-07-21 r48968)
i386-pc-mingw32

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252  [3] 
LC_MONETARY=German_Germany.1252 LC_NUMERIC=C  [5] 
LC_TIME=German_Germany.1252  
attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 
###


# case 1
x1 <- list(1, 2)
names(x1)[2]
# returns NULL

# case 2
x2 <- list(foo=1, 2)
names(x2)[2]
# returns ""

# case 3
x3 <- list(1, 2)
names(x3)[1] <- "foo"
names(x3)[2]
# returns NA

###

Although I don't find it particularly good that 1) and 2)  behave 
differently, I can very well understand what happens and accept this.


I may also understand (on a technical level) what happens in 3), but I 
find it very disturbing that these lines


x2 <- list(foo=1, 2)
x3 <- list(1, 2)
names(x3)[1] <- "foo"

produce different results.

?names says

" The name |""| is special: it is used to indicate that there is no name 
associated with an element of a (atomic or generic) vector. Subscripting 
by |""| will match nothing (not even elements which have no name).


A name can be character |NA|, but such a name will never be matched and 
is likely to lead to confusion."


If it "likely leads to confusion" why does the implementation use it?

Regards,

Bernd Bischl

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


Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

2009-08-04 Thread Martin Becker

Dear Ravi,

I suspect that, in general, you may be facing the limitations of machine 
accuracy (more precisely, IEEE 754 arithmetics on [64-bit] doubles) in 
your application. This is not a problem of R itself, but rather a 
problem of standard arithmetics provided by underlying C compilers/CPUs.
In fact, every operation in IEEE arithmetics (so, this is not really a 
problem only for complex numbers) may suffer from inexactness, a 
particularly difficult one is addition/subtraction. Consider the 
following example for real numbers (I know, it is not a very good one...):

The two functions

badfn <- function(x) 1-(1+x)*(1-x)
goodfn <- function(x) x^2

both calculate x^2 (theoretically, given perfect arithmetic). So, as you 
want to allow the user to 'specify the mathematical function ... in 
"any" form the user chooses', both functions should be ok.

But, unfortunately:

> badfn(1e-8)
[1] 2.220446049250313e-16
> goodfn(1e-8)
[1] 1e-16

I don't know what happens in matlab/octave/scilab for this example. They 
may do better, but probably at some cost (dropping IEEE arithmetic/do 
"clever" calculations should result in massive speed penalties, try 
evaluating   hypergeom([1,-99.9],[-49.9-24.9*I],(1+1.71*I)/2);   in 
Maple...).

Now, you have some options:

- assume, that the user is aware of the numerical inexactness of ieee 
arithmetics and that he is able to supply some "robust" version of the 
mathematical function.
- use some other software (eg., matlab) for the critical calculations 
(there is a R <-> Matlab interface, see package R.matlab on CRAN), if 
you are sure, that this helps.
- implement/use multiple precision arithmetics within R (Martin 
Maechler's Rmpfr package may be very useful: 
http://r-forge.r-project.org/projects/rmpfr/ , but this will slow down 
calculations considerably)


All in all, I think it is unfair just to blame R here. Of course, it 
would be great if there was a simple trigger to turn on multiple 
precision arithmetics in R. Packages such as Rmpfr may provide a good 
step in this direction, since operator overloading via S4 classes allows 
for easy code adaption. But Rmpfr is still declared "beta", and it 
relies on some external library, which could be problematic on Windows 
systems. Maybe someone else has other/better suggestions, but I do not 
think that there is an easy solution for the "general" problem.


Best wishes,

 Martin


Ravi Varadhan wrote:

Dear Martin,

Thank you for this useful trick.  However, we are interested in a "general"
approach for exact derivative computation.  This approach should allow the
user to specify the mathematical function that needs to be differentiated in
"any" form that the user chooses.  So, your trick will be difficult to
implement there.  Furthermore, do we know for sure that `exponentiation' is
the only operation that results in inaccuracy?  Are there other operations
that also yield inaccurate results for complex arithmetic?  


Hans Borchers also checked the computations with other free numerical
software, such as Octave, Scilab, Euler, and they all return exactly the
same results as Matlab.  It would be a shame if R could not do the same.  

It would be great if the R core could address the "fundamental" issue. 


Thank you.

Best regards,
Ravi.


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 


Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml

 






-Original Message-
From: Martin Becker [mailto:martin.bec...@mx.uni-saarland.de] 
Sent: Monday, August 03, 2009 5:50 AM

To: Ravi Varadhan
Cc: r-de...@stat.math.ethz.ch; hwborch...@googlemail.com
Subject: Re: [Rd] Inaccurate complex arithmetic of R (Matlab is accurate)

Dear Ravi,

the inaccuracy seems to creep in when powers are calculated. Apparently,
some quite general function is called to calculate the squares, and one can
avoid the error by reformulating the example as follows:

rosen <- function(x) {
  n <- length(x)
  x1 <- x[2:n]
  x2 <- x[1:(n-1)]
  sum(100*(x1-x2*x2)*(x1-x2*x2) + (1-x2)*(1-x2)) }

x0 <- c(0.0094, 0.7146, 0.2179, 0.6883, 0.5757, 0.9549, 0.7136, 0.0849,
0.4147, 0.4540) h <- c(1.e-15*1i, 0, 0, 0, 0, 0, 0, 0, 0, 0) xh <- x0 + h

rx <- rosen(xh)
Re(rx)
Im (rx)


I don't know which arithmetics are involved in the application you
mentioned, but writing some auxiliary function for the calculation of x^n
when x is complex and n is (a not too large) integer may solve some of the
numerical issues. A simple version is:

powN <- function(x,n) sapply(x,function(x) prod(rep(x,n)))

The corresponding summation in 'rosen' would then read:

sum(100*powN(x1-powN(x2,2),2) + powN(1-x2,2))


HTH

Re: [Rd] What changed in the R Windows interface from v2.6.2 to v2.7.0?

2009-08-04 Thread Duncan Murdoch

Mark Thyer wrote:

Dear R-devel,

 


I would like to launch the Rgui.exe from a Fortran console application (we
will call this FortranCon.exe), that I have written myself. To do this, I
send the command line "C:\Program Files\R\R-X.X.X\Rgui.exe" (where X.X.X is
the version number) as an argument to the
Windows API function CreateProcess (see
http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx) 

 


I use the createprocess command because I want the Rgui.exe and the Fortran
console application to run in parallel. 

 


I have done this before with other executables (e.g. Tinn-R.exe,
textpad.exe) and there hasn't been a problem.

 

But with the current version of R(v2.9.1), there is a problem. 

 


The problem is that after Rgui.exe is launched by FortranCon.exe, the
console window for FortanCon.exe does not close properly when it finishes
running. 


I have to manually close it, by clicking on the topright X on the window.
When I do this the Rgui.exe window also closes - which again is different to
normal, and then the Windows EndProgram dialog comes up and asks me whether
I wish to close FortranCon.exe

 


I have experimented with different versions of R, and this problem only
occurs in R(>=v2.7.0)

 


If I launch Rgui.exe for v2.6.2, then the FortranCon.exe window closes
automatically when it finishes and the Rgui.exe window remains open - this
is the behaviour I expect and want to happen. Indeed, this is what usually
happens If I launch other executables using the CreateProcess function.

 


This error does not occur if I launch Rgui.exe from a Fortran windows
application. (as opposed to console application) 

 


I am running R on Windows XP (Service Pack 3) 32-bit (I have also found the
problem occurs using 64-bit Windows XP). The FortranCon.exe is complied and
linked by Intel Visual Fortran IVF11.1.035 and Visual Studio 2008.

 


So my query is. What has changed in the R Windows interface from v2.6.2 to
v2.7.0 to cause this problem. I had a look at the CHANGES for R2.7.0 and I
couldn't see anything the instantly could cause this problem. 
  


I don't remember any change that would cause this, though there were a 
lot of changes.  You might need to build some intermediate versions 
(checkout from the Subversion repository and build) in order to narrow 
it down. 2.6.x split from the trunk in revision 42766, and 2.7.0 was 
released in revision 45426, so you've got the unpleasant possibility of 
a search through a few thousand versions.  (I recommend a binary search!)


In future you could avoid problems like this by staying up to date:  If 
you'd noticed this when 2.7.0 was released in April, 2008 (or helped 
during testing before release), our memory would have been fresher.


Duncan Murdoch


 

Any help on this matter is greatly appreciated. 

 


The ability to launch R from a Fortran application is important for the
usability of the RFortran software library (www.rfortran.org
 ) that we are developing. 

 


Cheers,

Mark

 


_

Dr Mark Thyer

Senior Lecturer in Environmental Engineering

Discipline of Civil, Surveying and Environmental Engineering

School of Engineering, University of Newcastle

Callaghan, NSW, Australia 2308

T: 02 4921 6057

F: 02 4921 6991

E: mark.th...@newcastle.edu.au

W:
www.newcastle.edu.au/school/engineering/our_staff/profiles/thyer_mark.html

 


"It is easy to lie with statistics, but it is difficult to tell the truth
without them." Andrejs Dunkels

 

 

 

 

 



[[alternative HTML version deleted]]

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



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


[Rd] save() does not issue an error if it tries to write on overfull hdd (PR#13866)

2009-08-04 Thread benjamin . hofner
Full_Name: Benjamin Hofner
Version: 2.9.1
OS: Ubuntu 8.04
Submission from: (NULL) (141.67.245.196)


Hi,

if I try to save (via save(...), write.table(...), etc.) some data on a full (!)
disc (free disc space was ~ 20Kb) the save command seems to finish without an
error. However, if you try to load the saved file to R again different errors
(depending on the load routine) occur. I think it would be very helpful for
useRs if an error is returned if the disc is full (similar to the error if the
user has no write permission).


> version
   _   
platform   i486-pc-linux-gnu   
arch   i486
os linux-gnu   
system i486, linux-gnu 
status 
major  2   
minor  9.1 
year   2009
month  06  
day26  
svn rev48839   
language   R   
version.string R version 2.9.1 (2009-06-26)

> setwd("/path_to_full_directory/")
> test <- 1:10

> save("test", file="testdata.RData") # no error is returned here
> load("testdata.RData")
Fehler in if (!grepl("RD[AX]2\n", magic)) { : Argument hat Länge 0

> write.table(test, "test.csv") # no error is returned here
> read.table("test.csv")
Fehler in read.table("test.csv") : keine Zeilen im Input verfügbar

Best wishes,
  Benjamin

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