-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
I'm developing an R package using S7 classes and encountering issues documenting subsetting methods ([
, [<-
, [[
, [[<-
) with devtools::document()
and devtools::check()
.
The Problem
I've tried two approaches to document S7 methods:
Approach 1: Basic documentation (fails)
#' Extract a view from the vector
#' blah blah blah
#' @export
S7::method(`[`, cool_vector) <- function(x, i, ...) {
x@vec[i]
}
error with devtools::document()
Block must have a @name.
ℹ Either document an existing object or manually specify with @name
Approach 2: Adding @name (fails differently)
#' Extract a view from the vector
#' @name `[`
#' blah blah blah
#' @export
S7::method(`[`, cool_vector) <- function(x, i, ...) {
x@vec[i]
}
which documents successfully but devtools::check()
gives:
W checking for missing documentation entries ...
Undocumented code objects:
‘[’ ‘[<-’
Additionally examples fail
Error in check_subsettable(x) : S7 objects are not subsettable.
Reproducible example
Here is a complete reproducible example:
#' My class
#'
#' A test class for subsetting methods
#'
#' @param vec A vector
#' @return An object of class `cool_vector`
#' @export
cool_vector <- S7::new_class("cool_vector",
properties = list(
vec = S7::class_any
))
#' Extract element from vector
#'
#' @param x A `cool_vector`
#' @param i The position to extract
#' @return vec[i]
#' @examples
#' cv <- cool_vector(1:10)
#' cv[5]
#' @export
S7::method(`[`, cool_vector) <- function(x, i, ...) {
x@vec[i]
}
#' Replace element in vector
#'
#' @param x A `cool_vector`
#' @param i The position to replace
#' @param value Replacement value
#' @return Modified `cool_vector`
#' @examples
#' cv <- cool_vector(1:10)
#' cv[5] <- 100
#' @export
S7::method(`[<-`, cool_vector) <- function(x, i, ..., value) {
x@vec[i] <- value
x
}
I came to ask here as the vignette on developing packages requests that any questions on package development should be done here.
Also I think that this issue is different from the other issues open for roxygen2 requesting guidance on documenting the classes themselves as this refers to methods.
Metadata
Metadata
Assignees
Labels
No labels