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

2023-07-07 Thread Martin Maechler
> Mikael Jagan 
> on Thu, 6 Jul 2023 11:32:00 -0400 writes:

> 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


Thank you, Mikael!

Indeed, as I see that it seems not even more costly than using sys.call(),
*and* because you gave me a case, where the previous, even
updated code, even lead to an error:

  > mapply(as.data.frame, x=1:10, row.names=letters[1:10])
  Error in (c1 <- sys.call(-1L)[[1L]]) != quote(as.data.frame) :
  comparison (!=) is possible only for atomic and list types

I have amended the code, using sys.function(-1L) in the first check
which does fix the above error and catches more false positives.

This is now in  R-devel svn rev >=  84653
and is planned to eventually be ported to the R 4.3.x series,
i.e., currently "R 4.3.1 patched".

Martin

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


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


[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