Re: [Rd] Rscript fails with some packages (for example, h5)

2017-12-27 Thread Duncan Murdoch

On 26/12/2017 9:40 AM, Dirk Eddelbuettel wrote:


On 26 December 2017 at 22:14, Sun Yijiang wrote:
| Thanks for the solution.  Now I know the work-arounds, but still don't
| quite get it. Why does R_DEFAULT_PACKAGES has anything to do with
| library(methods)?

Because it governs which packages are loaded by default.  And while R also
loads 'methods', Rscript does not. Source of endless confusion.


Mostly irrelevant correction of the jargon:  that setting controls which 
packages are "attached" by default.  library(h5) would be enough to load 
methods, because h5 imports things from methods.  But loading doesn't 
put a package on the search list.  library(methods) both loads methods 
(if it hasn't already been loaded), and attaches it.




| If library(h5) works, it should just work, not depend on an environment 
variable.

Every package using S4 will fail under Rscript unless 'methods' explicitly.


That's not quite true (or quite English, as per fortune(112)).  The 
"gmp" package imports methods, and it works in Rscript.  What doesn't 
work is to expect library(h5) or library(gmp) to cause methods functions 
like show() to be available to the user.


There is a way to do that, but it is discouraged nowadays. My ancient 
package "orientlib" depends on methods, and that forces methods to be 
attached so show() works in Rscript.  ("Depends" is used in the 
DESCRIPTION file sense.)  h5 doesn't "depend" on methods, it "imports" 
methods.





| Rscript is not consistent with R, that's my confusion.

Indeed. And you are not the first person confused by it.


And that's still true, and less irrelevant than my corrections.

Duncan Murdoch

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


Re: [Rd] Rscript fails with some packages (for example, h5)

2017-12-27 Thread Dirk Eddelbuettel

Duncan,

Very nice tutorial. However it does NOT take away from the fact that _very_
simple_ scripts (like the one posted by Sun at the beginning of this thread)
simply _fail_ in error under Rscript.

Whereas they don't under R or r.

The R environment ships an interpreter meant for command-line and scripting
use which fails on simple scripts that happen to use S4. But I am tired of
arguing for reversing this as I have gotten nowhere in all those years.

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

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


Re: [Rd] Rscript fails with some packages (for example, h5)

2017-12-27 Thread Sun Yijiang
Thanks for the details. I’m new to R, and I’m not blaming anything here,
just that I’m still not clear what good it makes to keep this inconsistency
between R and Rscript. To me (and probably to many others from Perl/Python
etc.), this is shockingly weird. I can live with that, and I also want to
know why.

Steve
Dirk Eddelbuettel 于2017年12月27日 周三21:15写道:

>
> Duncan,
>
> Very nice tutorial. However it does NOT take away from the fact that _very_
> simple_ scripts (like the one posted by Sun at the beginning of this
> thread)
> simply _fail_ in error under Rscript.
>
> Whereas they don't under R or r.
>
> The R environment ships an interpreter meant for command-line and scripting
> use which fails on simple scripts that happen to use S4. But I am tired of
> arguing for reversing this as I have gotten nowhere in all those years.
>
> Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
>

[[alternative HTML version deleted]]

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

[Rd] Numerical stability in chisq.test

2017-12-27 Thread Jan Motl
The chisq.test on line 57 contains following code:
STATISTIC <- sum(sort((x - E)^2/E, decreasing = TRUE))

However, based on book "Accuracy and stability of numerical algorithms" 
available from:

http://ftp.demec.ufpr.br/CFD/bibliografia/Higham_2002_Accuracy%20and%20Stability%20of%20Numerical%20Algorithms.pdf
Table 4.1 on page 89, it is better to sort the data in increasing order than in 
decreasing order, when the data are non-negative.

An example:
x = matrix(c(rep(1.1, 1)), 10^16, nrow = 10001, ncol = 1)# We 
have a vector with 1*1.1 and 1*10^16
c(sum(sort(x, decreasing = TRUE)), sum(sort(x, decreasing = FALSE)))
The result:
100010996 100011000
When we sort the data in the increasing order, we get the correct result. If we 
sort the data in the decreasing order, we get a result that is off by 4.

Shouldn't the sort be in the increasing order rather than in the decreasing 
order?

Best regards,
Jan Motl


PS: This post is based on discussion on 
https://stackoverflow.com/questions/47847295/why-does-chisq-test-sort-data-in-descending-order-before-summation
 and the response from the post to r-h...@r-project.org.
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Rscript fails with some packages (for example, h5)

2017-12-27 Thread Duncan Murdoch

On 27/12/2017 9:11 AM, Sun Yijiang wrote:

Thanks for the details. I’m new to R, and I’m not blaming anything here,
just that I’m still not clear what good it makes to keep this inconsistency
between R and Rscript. To me (and probably to many others from Perl/Python
etc.), this is shockingly weird. I can live with that, and I also want to
know why.


As Dirk said, the argument was that the methods package used to take a 
long time to load, and many uses of Rscript shouldn't have to pay that 
time cost.  I don't know whether that's still true or not.  Dirk and I 
agree that the inconsistency between R and Rscript is undesirable, but 
neither of us is in a position to change it, or thinks it's worth the 
effort to argue for a change.


Duncan




Steve
Dirk Eddelbuettel 于2017年12月27日 周三21:15写道:



Duncan,

Very nice tutorial. However it does NOT take away from the fact that _very_
simple_ scripts (like the one posted by Sun at the beginning of this
thread)
simply _fail_ in error under Rscript.

Whereas they don't under R or r.

The R environment ships an interpreter meant for command-line and scripting
use which fails on simple scripts that happen to use S4. But I am tired of
arguing for reversing this as I have gotten nowhere in all those years.

Dirk

--
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org





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