Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@describeIn throws error when used with S4 methods. #1370

Closed
ralmond opened this issue Jun 22, 2022 · 5 comments
Closed

@describeIn throws error when used with S4 methods. #1370

ralmond opened this issue Jun 22, 2022 · 5 comments
Labels
feature a feature request or enhancement rd ✍️
Milestone

Comments

@ralmond
Copy link

ralmond commented Jun 22, 2022

I thought a perfect example of a use of @describeIn was describing generic functions and methods in a class definition.

So here is a code snippet which I thought would work:

#'
#'
#' This is a lightweight class meant to be extended.  It contains a
#' single field for a mongo identifier, which can be accessed using
#' the `m_id()` method.  It is meant to store something that is a
#' record in a mongo collection, where `_id` is the mongo identifier.
#'
#'
#'
#' @name MongoRec-class
#' @aliases MongoRec-class m_id,MongoRec-method m_id<-,MongoRec-method
#' as.jlist,MongoRec,list-method as.json,MongoRec-method
#' @docType class
#' @section Objects from the Class:
#'
#' Objects can be created by calls to the \code{\link{MongoRec}()} function.
#' @author Russell G. Almond
#' @seealso \code{\link{MongoRec}()} --- constructor
#' \code{\link{as.json}},
#' \code{\link{parseObject}}, \code{\link{saveRec}}, \code{\link{getOneRec}}
#' @keywords classes
#' @examples
#'
#' showClass("MongoRec")
#'
#' @exportClass("MongoRec")
setClass("MongoRec",
         slots=c("_id"="character"    #Mongo ID
                 ))
#' @describeIn MongoRec Accessor for Mongo id.
setGeneric("m_id",function(x) standardGeneric("m_id"))

#' @describeIn MongoRec Accessor for Mongo id.
setGeneric("m_id<-",function(x, value) standardGeneric("m_id<-"))

#' @describeIn MongoRec Accessor for Mongo id.
setMethod("m_id","MongoRec", function(x) x@"_id")

#' @describeIn MongoRec  Accessor for Mongo id.
setMethod("m_id<-","MongoRec", function(x,value) {
  names(value) <- "oid"
  x@"_id" <- value
  x})

However, I get

Error in merge.rd_section_minidesc(self$get_section(type), section) : 
  identical(x$value$type, y$value$type) is not TRUE

(This is the same error referenced in my previous issue, about there not being sufficient context information with the error).

However, I think this should be a case where @describeIn works (or at least it needs better documentation as to what works and why).

Note, I get a similiar error, if I move the documentation to the m_id generic function and try to use @describeIn m_id for the other generic and the two methods.

@ralmond ralmond changed the title @describeIn generates throws error when used with S4 methods. @describeIn throws error when used with S4 methods. Jun 22, 2022
@hadley
Copy link
Member

hadley commented Jun 24, 2022

Would you minding having a go at creating a reprex following the advice in https://github.com/r-lib/roxygen2/blob/main/.github/SUPPORT.md#making-a-reprex ?

@hadley hadley added the reprex needs a minimal reproducible example label Jun 24, 2022
@ralmond
Copy link
Author

ralmond commented Jun 24, 2022

library(roxygen2)
roc_proc_text(rd_roclet(),"
#' Class \\dQuote{MongoRec}
#'
setClass('MongoRec',
         slots=c('_id'='character'    #Mongo ID
                 ))
                 
#' @describeIn MongoRec Accessor for Mongo id.
setGeneric('m_id',function(x) standardGeneric('m_id'))

#' @describeIn MongoRec Accessor for Mongo id.
setMethod('m_id','MongoRec', function(x) x@'_id')

")
#> Error in merge.rd_section_minidesc(self$get_section(type), section): identical(x$value$type, y$value$type) is not TRUE

Here you go. The issue appears to be related to having a generic function and a method both documented in the same object.

@hadley hadley added feature a feature request or enhancement rd ✍️ and removed reprex needs a minimal reproducible example labels Jul 10, 2022
@hadley
Copy link
Member

hadley commented Jul 10, 2022

Now we get a better warning, but should consider supporting this:

library(roxygen2)
x <- roc_proc_text(rd_roclet(),"
#' Class \\dQuote{MongoRec}
#'
setClass('MongoRec',
         slots=c('_id'='character'    #Mongo ID
                 ))
                 
#' @describeIn MongoRec Accessor for Mongo id.
setGeneric('m_id',function(x) standardGeneric('m_id'))

#' @describeIn MongoRec Accessor for Mongo id.
setMethod('m_id','MongoRec', function(x) x@'_id')

")
#> Warning: [<text>:12] Don't know how to combine @describeIn types "function" and
#> "class"

Created on 2022-07-10 by the reprex package (v2.0.1)

@hadley
Copy link
Member

hadley commented Jul 16, 2022

That PR makes it work, but it doesn't give particularly nice labels so re-opening.

@hadley hadley reopened this Jul 16, 2022
hadley added a commit that referenced this issue Jul 16, 2022
@hadley
Copy link
Member

hadley commented Jul 16, 2022

With current PR:

library(roxygen2)
roc_proc_text(rd_roclet(),"
#' Class \\dQuote{MongoRec}
#'
setClass('MongoRec',
         slots=c('_id'='character'    #Mongo ID
                 ))
                 
#' @describeIn MongoRec Accessor for Mongo id.
setGeneric('m_id',function(x) standardGeneric('m_id'))

#' @describeIn MongoRec Accessor for Mongo id.
setMethod('m_id','MongoRec', function(x) x@'_id')

")[[1]]
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \docType{class}
#> \name{MongoRec-class}
#> \alias{MongoRec-class}
#> \alias{m_id}
#> \alias{m_id,MongoRec-method}
#> \title{Class \dQuote{MongoRec}}
#> \usage{
#> m_id(x)
#> 
#> \S4method{m_id}{MongoRec}(x)
#> }
#> \description{
#> Class \dQuote{MongoRec}
#> }
#> \section{Methods (by generic)}{
#> \itemize{
#> \item \code{m_id(MongoRec)}: Accessor for Mongo id.
#> 
#> }}
#> \section{Functions}{
#> \itemize{
#> \item \code{m_id()}: Accessor for Mongo id.
#> 
#> }}

Created on 2022-07-16 by the reprex package (v2.0.1)

@hadley hadley closed this as completed in 07e4d1d Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement rd ✍️
Projects
None yet
Development

No branches or pull requests

2 participants