Re: [Rd] Rmpfr: build vector sequentially -- c(.) not working

2018-10-26 Thread Martin Maechler
I've been asked in private,
but am answering in public so others can comment / or find this
answer in the future after a web search.

This is about the package 'Rmpfr' (R interface to MPFR,
the GNU C library for arbitrary precise numbers).

> How can you build a vector of mpfr numbers sequentially?
> Typically I would do something like the following (and try to
> replace the for loop with some sort of apply construct)
> 
> vec <- NULL
> for(...) {
>...
>vec <- c(vec, vec.new)
> }

Dear Jerry,

In general the above is *bad* R code in the sense that it is
unnecessarily inefficient.
In a typical for() loop you know the length of the result in
advance, and

 vec <- numeric(n)
 for(i in seq_along(vec)) {

   vec[i] <- .
 }

is *MUCH* faster than your construct  when  n  is not small.

Still, I understand that you would expect  mpfr numbers to work as
well as many other R objects here -- and they don't :

> However, this does not work with mpfr's.  For instance
>c(NULL, 1:3)
> is equivalent to
>1:3
> 
> But
>c(NULL, mpfr(1:3,100))
> is not even the same class as
>mpfr(1:3,100)

Indeed.  One can consider this to be unfortunate, but it's
nothing I can change as author of 'Rmpfr'.

Rather, this is a shortcoming of R's current implementation of  c()
which I think may be very hard to be changed in R without either
losing to much speed or changing semantic in a too radical way.
[but I'm happy if I'm  proven wrong here  !!  ==> that's why posting to R-devel]

- - - -

Anyway, now to solve your problem, if you really want to do
something like your original code, you can do it like this :

mNUL <- mpfr(logical())  # instead of 'NULL'

Then, e.g.,

 vec <- mNUL
 for(i in 1:10) {
vec <- c(vec, mpfr(i^2, 88))
 }

works fine.

In the next version of Rmpfr, both

   as(NULL, "mpfr")
   mpfr(NULL)

will also give the 'mNUL' above.

I hope you enjoy using Rmpfr!

Best regards,
Martin


Martin Maechler
ETH Zurich

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


[Rd] Small typo in log output of src/library/tools/R/check.R:check_pkg

2018-10-26 Thread Sebastian Gibb
Dear R-core members,

there is a small typo in the log output of `check_pkg` in
src/library/tools/R/check.R. Instead of "timestanps" it should be "timestamps":

Best wishes,

Sebastian


svn diff

Index: src/library/tools/R/check.R
===
--- src/library/tools/R/check.R (revision 75499)
+++ src/library/tools/R/check.R (working copy)
@@ -431,7 +431,7 @@
  "FALSE"))) {
 now_local <- Sys.time()
 any <- FALSE
-checkingLog(Log, "for future file timestanps")
+checkingLog(Log, "for future file timestamps")
 ## allow skipping clock check on CRAN incoming systems
 if(config_val_to_logical(Sys.getenv("_R_CHECK_SYSTEM_CLOCK_", 
"TRUE"))) {
 ## First check time on system running 'check',

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


Re: [Rd] small bug in formatC?

2018-10-26 Thread Martin Maechler
> David Hugh-Jones 
> on Thu, 25 Oct 2018 17:46:47 +0100 writes:

> formatC(0.0001, digits = 3, format = "f", zero.print="< 0.01")
> Error in strrep(" ", nc - i1) : invalid 'times' value
> 
> The problem, if it is one, is in .format.zeros:
> .format.zeros("0.000", "xx")
> Error in strrep(" ", nc - i1) : invalid 'times' value
> 
> R version 3.5.1.
> 
> David

Thank you, David.

Yes, this looks like a bug / wrong assumption in  .format.zeros().
I will have a look (and report back).

Martin Maechler
ETH Zurich and R Core

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


Re: [Rd] Bug report for sealClass() in Core-maintained package "methods"

2018-10-26 Thread Gower, Adam
Hello,
I was just reminded from a comment in some code that I had submitted this bug 
report last year, but it does not appear to have been addressed in R 3.5.0.
Can this please be fixed, or is there a specific reason that it cannot be 
addressed?
Thanks,
Adam

From: Gower, Adam
Sent: Monday, June 19, 2017 11:56 AM
To: 'r-devel@r-project.org'
Subject: Bug report for sealClass() in Core-maintained package "methods"

Hello,

I have found that I cannot use sealClass() without specifying the 'where' 
argument.
I have found this issue in R 3.2.3 and R 3.4.0.
For example:
> setClass("foo", slots=c(name="character", age="integer"))
> isSealedClass("foo")
[1] FALSE
> sealClass("foo")
Error in list2env(list(), NULL, ) :
  names(x) must be a character vector of the same length as x
> isSealedClass("foo")
[1] FALSE
> sealClass("foo", where=.GlobalEnv)
> isSealedClass("foo")
[1] TRUE

I found that this is because sealClass() includes the following line:
if (missing(where)) where <- findClass(Class, unique = "sealing the class", 
where = where)

Because findClass() always returns a list (even if argument 'unique' contains a 
character string), this assigns a list of length 1 to variable 'where'.
This then throws an error in the subsequent line
assignClassDef(Class, classDef, where)

For this reason, the abovementioned line should instead read:
if (missing(where)) where <- findClass(Class, unique = "sealing the class", 
where = where)[[1]]

Thanks very much,
Adam Gower
ago...@bu.edu


[[alternative HTML version deleted]]

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


Re: [Rd] Bug report for sealClass() in Core-maintained package "methods"

2018-10-26 Thread Duncan Murdoch

On 26/10/2018 10:28 AM, Gower, Adam wrote:

Hello,
I was just reminded from a comment in some code that I had submitted this bug 
report last year, but it does not appear to have been addressed in R 3.5.0.
Can this please be fixed, or is there a specific reason that it cannot be 
addressed?


You're reporting in the wrong place.  Write to R-devel about 
inconsequential things like typos in help pages, or when you're not sure 
something is a bug.  Put bug reports that you care about on the bug 
reporting site, bugs.r-project.org.


The https://www.r-project.org/bugs.html page suggests that reports here 
are sufficient, but it's wrong.  Usually they are not.


Duncan Murdoch


Thanks,
Adam

From: Gower, Adam
Sent: Monday, June 19, 2017 11:56 AM
To: 'r-devel@r-project.org'
Subject: Bug report for sealClass() in Core-maintained package "methods"

Hello,

I have found that I cannot use sealClass() without specifying the 'where' 
argument.
I have found this issue in R 3.2.3 and R 3.4.0.
For example:

setClass("foo", slots=c(name="character", age="integer"))
isSealedClass("foo")

[1] FALSE

sealClass("foo")

Error in list2env(list(), NULL, ) :
   names(x) must be a character vector of the same length as x

isSealedClass("foo")

[1] FALSE

sealClass("foo", where=.GlobalEnv)
isSealedClass("foo")

[1] TRUE

I found that this is because sealClass() includes the following line:
if (missing(where)) where <- findClass(Class, unique = "sealing the class", 
where = where)

Because findClass() always returns a list (even if argument 'unique' contains a 
character string), this assigns a list of length 1 to variable 'where'.
This then throws an error in the subsequent line
assignClassDef(Class, classDef, where)

For this reason, the abovementioned line should instead read:
if (missing(where)) where <- findClass(Class, unique = "sealing the class", 
where = where)[[1]]

Thanks very much,
Adam Gower
ago...@bu.edu


[[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


Re: [Rd] Bug report for sealClass() in Core-maintained package "methods"

2018-10-26 Thread Gower, Adam
Thanks very much for the clarification, Duncan - I appreciate it.  Will do.
Best,
Adam

-Original Message-
From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] 
Sent: Friday, October 26, 2018 9:30 PM
To: Gower, Adam; r-devel@r-project.org
Subject: Re: [Rd] Bug report for sealClass() in Core-maintained package 
"methods"

On 26/10/2018 10:28 AM, Gower, Adam wrote:
> Hello,
> I was just reminded from a comment in some code that I had submitted this bug 
> report last year, but it does not appear to have been addressed in R 3.5.0.
> Can this please be fixed, or is there a specific reason that it cannot be 
> addressed?

You're reporting in the wrong place.  Write to R-devel about 
inconsequential things like typos in help pages, or when you're not sure 
something is a bug.  Put bug reports that you care about on the bug 
reporting site, bugs.r-project.org.

The https://www.r-project.org/bugs.html page suggests that reports here 
are sufficient, but it's wrong.  Usually they are not.

Duncan Murdoch

> Thanks,
> Adam
> 
> From: Gower, Adam
> Sent: Monday, June 19, 2017 11:56 AM
> To: 'r-devel@r-project.org'
> Subject: Bug report for sealClass() in Core-maintained package "methods"
> 
> Hello,
> 
> I have found that I cannot use sealClass() without specifying the 'where' 
> argument.
> I have found this issue in R 3.2.3 and R 3.4.0.
> For example:
>> setClass("foo", slots=c(name="character", age="integer"))
>> isSealedClass("foo")
> [1] FALSE
>> sealClass("foo")
> Error in list2env(list(), NULL, ) :
>names(x) must be a character vector of the same length as x
>> isSealedClass("foo")
> [1] FALSE
>> sealClass("foo", where=.GlobalEnv)
>> isSealedClass("foo")
> [1] TRUE
> 
> I found that this is because sealClass() includes the following line:
> if (missing(where)) where <- findClass(Class, unique = "sealing the class", 
> where = where)
> 
> Because findClass() always returns a list (even if argument 'unique' contains 
> a character string), this assigns a list of length 1 to variable 'where'.
> This then throws an error in the subsequent line
> assignClassDef(Class, classDef, where)
> 
> For this reason, the abovementioned line should instead read:
> if (missing(where)) where <- findClass(Class, unique = "sealing the class", 
> where = where)[[1]]
> 
> Thanks very much,
> Adam Gower
> ago...@bu.edu
> 
> 
>   [[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