Re: [Rd] logic tweak needed for as.data.frame. deprecation warning

2023-07-06 Thread Mikael Jagan

Another issue raised in the earlier thread is that as.data.frame.POSIXlt
still calls as.data.frame.POSIXct.  Hence another path to a false positive
deprecation warning would be:

> Sys.setenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_" = TRUE)
> as.data.frame(as.POSIXlt(.POSIXct(0, "UTC")))
  as.POSIXlt(.POSIXct(0, "UTC"))
1 1970-01-01
Warning message:
Direct call of 'as.data.frame.POSIXct()' is deprecated.  Use 
'as.data.frame.vector()' or 'as.data.frame()' instead


as.data.frame.POSIXlt could simply change to using as.data.frame.vector.

I glanced at the other non-deprecated as.data.frame. and did not
see other usage of the deprecated ones ... a more systematic check could
be worth doing.

Mikael

On 2023-07-06 11:32 am, Mikael Jagan wrote:

Continuing the thread started on R-package-devel, here:
https://stat.ethz.ch/pipermail/r-package-devel/2023q3/009307.html

The logic of the now soft-deprecated as.data.frame.,

  > body(as.data.frame.integer)[[2L]]
if ((sys.nframe() <= 1L || sys.call(-1L)[[1L]] != quote(as.data.frame)) &&
  nzchar(Sys.getenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_")))
.Deprecated(msg = gettextf("Direct call of '%s()' is deprecated.  Use '%s()' or
'%s()' instead",
  "as.data.frame.integer", "as.data.frame.vector", "as.data.frame"))

may need adjustment to avoid false positives such as this one:

  > Sys.setenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_" = TRUE)
  > f <- as.data.frame
  > f(0L)
0L
1  0
Warning message:
Direct call of 'as.data.frame.integer()' is deprecated.  Use
'as.data.frame.vector()' or 'as.data.frame()' instead

i.e., the condition sys.call(-1L)[[1L]] != quote(as.data.frame) is not precise
enough ... would !identical(sys.function(-1L), as.data.frame) work instead?

Mikael


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


Re: [Rd] Warning 'as.data.frame.POSIXct()' is deprecated

2023-07-06 Thread Martin Maechler
> Tim Taylor 
> on Thu, 6 Jul 2023 15:11:41 +0100 writes:

> Ah yes ... and reading the as.data.frame help we see (emphasis mine):
> "... Direct calls to as.data.frame.() are still possible (*base 
> package!*), for 12 atomic base classes, but will deprecated ..."

> So it does seem that a lot of these warnings are triggered by base R and 
> updating this code may be a work in progress.


> A little tangential (but related) to this though is still the fact that 
> we can trigger the warning with:

> lapply(Sys.Date(), as.data.frame)

> so I wonder if the code in base/R/zzz.R 
> 
(https://github.com/wch/r-source/blob/9f1940663f902174034a01197e55fd17c767213a/src/library/base/R/zzz.R#L664-L686)
 
> does need tweaking?

Yes, thank you, Tim for your analysis.
I've started looking at the issue a couple of hours ago,
{notably as I am the originator of the issue ...}

> At this stage this is probably more a question for R-devel though.

> Tim

(( not only at this stage. This would have belonged there from the
   start but nothing is perfect
   ==> This reply now *GOES* to R-devel ))


Yes, this a buglet / imperfection in the deprecation warnings.
I have spent already time to fix the  lapply() case {and similar} cases.
In the mean time there *is* also a very related message on
R-devel by Mikael Jagan.

As the plan was that this is only "ad interim", namely
before those explicit  as.data.frame. methods will be
completely gone from base -- because they are all currently
identical(*) to as.data.frame.vector(),
I did add that hack in zzz.R  to create deprecation warnings
that should be correct most of the time - unless people do funny things.
--
*) apart from the fact that 12 method functions all got their deprec.warning.


> On 06/07/2023 14:42, Enrico Schumann wrote:
>> On Thu, 06 Jul 2023, Vincent van Hees writes:
>> 
>>> Thanks, in that case the REPLEX for the issue may need to be:
>>> 
 remember = Sys.getenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_")
 Sys.setenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_" = TRUE)
 data.frame(time = Sys.time())
>>> time
>>> 1 2023-07-06 14:29:37
 data.frame(time = as.POSIXlt(Sys.time()))
>>> time
>>> 1 2023-07-06 14:29:37
>>> Warning message:
>>> Direct call of 'as.data.frame.POSIXct()' is deprecated.  Use
>>> 'as.data.frame.vector()' or 'as.data.frame()' instead
 Sys.setenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_" = remember)
>> 
>> I think it happens because
>> 
>> data.frame()
>> 
>> calls 'as.data.frame.POSIXlt' (per its S3-class), which
>> in turn directly calls 'as.data.frame.POSIXct':
>> 
>> ## as.data.frame.POSIXlt
>> function (x, row.names = NULL, optional = FALSE, ...)
>> {
>> value <- as.data.frame.POSIXct(as.POSIXct(x), row.names,
>> optional, ...)
>> if (!optional)
>> names(value) <- deparse1(substitute(x))
>> value
>> }
>> 
>> 
>> Kind regards
>> Enrico

Indeed, thank you, Enrico!

That's another such case, that my "hack" (see above) overlooked;
somewhat embarrassingly, but also astonishingly to me as I hoped
to find relevant cases by warnings appearing within the base R
checks...  {and it is I think even easier to fix than the
lapply(.)  case..}.

Martin


Martin Maechler
ETH Zurich  and  R Core team


>>> Vincent
>>> 
>>> On Thu, 6 Jul 2023 at 10:41, Tim Taylor 

>>> wrote:
>>> 
 Apologies - I've not had enough caffeine just yet. The reprex below
 highlights the issue but I think the code which implemented the change
 *may* need tweaking not lapply.
 
 Tim
 
 On 06/07/2023 09:26, Tim Taylor wrote:
> This *may* be an issue in lapply.  Let's see what others day. Reprex
> below
> 
> Sys.setenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_" = TRUE)
> dat <- Sys.Date()
> as.data.frame(dat)
> #>  dat
> #> 1 2023-07-06
> lapply(dat, as.data.frame)
> #> Warning: Direct call of 'as.data.frame.Date()' is deprecated.  Use
> #> 'as.data.frame.vector()' or 'as.data.frame()' instead
> #> [[1]]
> #>   X[[i]]
> #> 1 2023-07-06
> 
> Tim
> 
> On 06/07/2023 08:54, Vincent van Hees wrote:
> Dear all,
>> 
> I see the following warning in my package test results:
>> 
> ```
> Warning
> Direct call of 'as.data.frame.POSIXct()' is deprecated.  Use
> 'as.data.frame.vector()' or 'as.data.frame()' instead
> ```
>> 
> The warning is not always there and I struggle to make it
> reproducible. I
> have encountered it in both Ubuntu 22.04 and in Windows 11, in both R
> 4.3.0
> and 4.3.1, in both RStudio and in an GitHub Actions environment (example
> 

[Rd] logic tweak needed for as.data.frame. deprecation warning

2023-07-06 Thread Mikael Jagan

Continuing the thread started on R-package-devel, here:
https://stat.ethz.ch/pipermail/r-package-devel/2023q3/009307.html

The logic of the now soft-deprecated as.data.frame.,

> body(as.data.frame.integer)[[2L]]
if ((sys.nframe() <= 1L || sys.call(-1L)[[1L]] != quote(as.data.frame)) &&
nzchar(Sys.getenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_"))) 
.Deprecated(msg = gettextf("Direct call of '%s()' is deprecated.  Use '%s()' or 
'%s()' instead",

"as.data.frame.integer", "as.data.frame.vector", "as.data.frame"))

may need adjustment to avoid false positives such as this one:

> Sys.setenv("_R_CHECK_AS_DATA_FRAME_EXPLICIT_METHOD_" = TRUE)
> f <- as.data.frame
> f(0L)
  0L
1  0
Warning message:
Direct call of 'as.data.frame.integer()' is deprecated.  Use 
'as.data.frame.vector()' or 'as.data.frame()' instead


i.e., the condition sys.call(-1L)[[1L]] != quote(as.data.frame) is not precise
enough ... would !identical(sys.function(-1L), as.data.frame) work instead?

Mikael

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


Re: [Rd] numeric_version doesn't like numeric versions anymore?

2023-07-06 Thread Sebastian Meyer
Please see  for the 
background. The documentation has always said that the input needs to be 
a character vector. Implicit conversion of numeric input to character is 
affected by R options (OutDec and scipen), but it is also error-prone in 
this context:


R> package_version("1.3") > 1.20
[1] TRUE

This now warns for a good reason in my opinion.

Best regards,

Sebastian Meyer


Am 06.07.23 um 08:37 schrieb Dipterix Wang:

Dear R devs,

I installed the recent devel R to test a package error when I intercept this 
warning when loading packages:

```
Warning in .make_numeric_version(x, strict, 
.standard_regexps()$valid_numeric_version) :
   invalid non-character version specification 'x' (type: double)
```

After a long debugging, I realize that `numeric_version` in base does not 
support numerical input x by default now.

A reproducible example:

R 4.4

```

numeric_version(1.5)

Warning in .make_numeric_version(x, strict, 
.standard_regexps()$valid_numeric_version) :
   invalid non-character version specification 'x' (type: double)
[1] ‘1.5’
```


R 4.3.1

```

numeric_version(1.5)

[1] ‘1.5’
```

According to help document, `strict=TRUE` should result in errors, then the 4.3 
behavior was actually incorrect. According to pkgload maintainer, Kurt has sent 
him an email to fix this, suggesting this on-going change is intentional.
  
May I ask is there any benefit of changing the behavior?


Thanks,
- D
[[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