Re: [Rd] undefined subclass warning

2021-06-30 Thread Martin Maechler
> Ben Bolker > on Wed, 30 Jun 2021 20:23:27 -0400 writes: >A colleague recently submitted a paper to JSS and was > advised to address the following warning which occurs when > their package > (https://CRAN.R-project.org/package=pcoxtime) is loaded: > Warning m

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Greg Minshall
Taras, > P.S. If you are wondering what I am trying to achieve here — we have a > very large codebase and I am trying to use environments as a type of > “poor man’s namespaces” to organize code in a modular fashion. But of > course it’s all pointless if I can’t get the generics to work > reliably.

Re: [Rd] On read.csv and write.csv

2021-06-30 Thread Simon Urbanek
Stephen, the "unhelpful" column are the row names. They are considered an important part of a data frame and therefore the default (row.names = TRUE) is to not lose them (as there is no way back once you do). If you don't want to preserve the row names you can simply set row.names=FALSE. Che

[Rd] undefined subclass warning

2021-06-30 Thread Ben Bolker
A colleague recently submitted a paper to JSS and was advised to address the following warning which occurs when their package (https://CRAN.R-project.org/package=pcoxtime) is loaded: Warning message: In .recacheSubclasses(def@className, def, env) : undefined subclass "numericVector" of

Re: [Rd] On read.csv and write.csv

2021-06-30 Thread Gabriel Becker
Hi Stephen, Personally, I don't have super strong feelings about this, but https://datatracker.ietf.org/doc/html/rfc4180#section-2 does say that the optional header line should have the same number of fields as the data records, so in as much as that is the "CSV specification", R's read.csv behavi

[Rd] On read.csv and write.csv

2021-06-30 Thread Stephen Ellison
Apologies if this is a well-worn question; I haven’t found it so far but there's a lot of r-dev and I may have missed it in the archives. In the mean time: I've managed to avoid writing csv files with R for a couple of decades but we're swopping data with a collaborator and I've tripped over an

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Taras Zakharko
I have opened a bug report here: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=18138 Regarding _R_S3_METHOD_LOOKUP_USE_TOPENV_AS_DEFENV_… maybe it’s a good time to consider purging it alltogether? This behavior appears to be completely undocumented and this variable is mentioned exactly t

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Duncan Murdoch
One error in my workaround: it also ignores _R_S3_METHOD_LOOKUP_USE_TOPENV_AS_DEFENV_. If that evaluates to FALSE, it shouldn't need to make any changes. Duncan Murdoch On 30/06/2021 9:20 a.m., Taras Zakharko wrote: Thanks Duncan, I will submit a bug report to R core then. Best, Taras O

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Taras Zakharko
Thanks Duncan, I will submit a bug report to R core then. Best, Taras > On 30 Jun 2021, at 14:16, Duncan Murdoch wrote: > > On 30/06/2021 7:37 a.m., Taras Zakharko wrote: >> Thats not how I read the code? Consider this snippet from registerS3method: >> genfun <- get(genname, envir = envir) >

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Duncan Murdoch
On 30/06/2021 7:37 a.m., Taras Zakharko wrote: Thats not how I read the code? Consider this snippet from registerS3method: genfun <- get(genname, envir = envir) if (.isMethodsDispatchOn() && methods::is(genfun, "genericFunction")) genfun <- methods::finalDefaultMethod(genfu

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Taras Zakharko
Thats not how I read the code? Consider this snippet from registerS3method: genfun <- get(genname, envir = envir) if (.isMethodsDispatchOn() && methods::is(genfun, "genericFunction")) genfun <- methods::finalDefaultMethod(genfun@default) if (typeof(genfun) == "closure"

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Duncan Murdoch
On 30/06/2021 7:23 a.m., Taras Zakharko wrote: I had another glance at the code and now I’m convinced that this is the bug in registerS3method(). Default R behavior (in objects.c) appears to be to look for method definitions in the top environment, not the defining environment, but registerS3m

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Duncan Murdoch
On 30/06/2021 6:51 a.m., Taras Zakharko wrote: @Duncan: .S3method() calls registerS3method() with appropriate environmental argument under the good, so that’s not the problem. Anyway, I’ve been doing some debugging and I think I have found the issue. The following snippet in src/objects.c (ht

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Taras Zakharko
I had another glance at the code and now I’m convinced that this is the bug in registerS3method(). Default R behavior (in objects.c) appears to be to look for method definitions in the top environment, not the defining environment, but registerS3method() registers the method in the defining envi

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Taras Zakharko
@Duncan: .S3method() calls registerS3method() with appropriate environmental argument under the good, so that’s not the problem. Anyway, I’ve been doing some debugging and I think I have found the issue. The following snippet in src/objects.c (https://github.com/wch/r-source/blob/ecc633b37d77f

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Joshua Ulrich
On Wed, Jun 30, 2021 at 5:17 AM Duncan Murdoch wrote: > > On 30/06/2021 5:22 a.m., Taras Zakharko wrote: > > Dear all, > > > > I have a generic function and a bunch of methods defined in a separate > > environment. Here is a reduced example: > > > > env <- local({ > > # define the gener

Re: [Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Duncan Murdoch
On 30/06/2021 5:22 a.m., Taras Zakharko wrote: Dear all, I have a generic function and a bunch of methods defined in a separate environment. Here is a reduced example: env <- local({ # define the generic function and the method myfun <- function(x) UseMethod("myfun") myfu

[Rd] S3 dispatch does not work for generics defined inside an environment

2021-06-30 Thread Taras Zakharko
Dear all, I have a generic function and a bunch of methods defined in a separate environment. Here is a reduced example: env <- local({ # define the generic function and the method myfun <- function(x) UseMethod("myfun") myfun.myclass <- function(x) print("called myfun.myclas