RConsortium / S7

S7: a new OO system for R
https://rconsortium.github.io/S7
Other
387 stars 33 forks source link

Unsure of how to document an S7 class in a package #348

Closed hrj21 closed 1 year ago

hrj21 commented 1 year ago

Hi all,

I am writing a package and want to implement an S7 class I'm calling an intelliframe. I've tried defining and documenting the class as below, but my feeling is that this isn't correct because when I call ?intelliframe, the help page shows each propery as being of class class_missing.

#' intelliframe class
#'
#' Defines the constructor function for the intelliframe S7 class. Not meant to be
#'   called directly by the user (see \code{\link{read_xmap}}).
#'
#'@slot metadata is this how I describe each of the properties?
#'
#'@export
#'
intelliframe <- S7::new_class(
  "intelliframe",
  properties = list(
    "metadata"       = S7::class_data.frame,
    "summary"        = S7::class_data.frame,
    "expected"       = S7::class_data.frame,
    "mfi"            = S7::class_data.frame,
    "mfi_avg"        = S7::class_data.frame,
    "mfi_cv"         = S7::class_data.frame,
    "mfi_sd"         = S7::class_data.frame,
    "result"         = S7::class_data.frame,
    "result_avg"     = S7::class_data.frame,
    "result_cv"      = S7::class_data.frame,
    "result_sd"      = S7::class_data.frame,
    "recovery"       = S7::class_data.frame,
    "recovery_avg"   = S7::class_data.frame,
    "messages"       = S7::class_data.frame,
    "curve_data"     = S7::class_data.frame,
    "analytes"       = S7::class_data.frame,
    "excluded_wells" = S7::class_data.frame
  )
)

I'm also not sure how to properly document methods for an S7 class in my package.

Sorry if this information is available somewhere but I've been going in circles for about an hour and would appreciate any help you can give.

hadley commented 1 year ago

You are doing it correctly: you can see what we have written so far at https://rconsortium.github.io/S7/articles/packages.html#documentation-and-exports.

Documenting methods is an open question; see #315 for details.

jeffkimbrel commented 12 months ago

I am also having the class_missing issue where documenting a class puts that in the .rd files instead of the S7 class name. Searching this repo for class_missing brings up many issues, but I don't really understand them.

It seems to be a special dispatch type when a user doesn't say what class their method attaches to, but 1) I am giving my class to all methods and 2) this is the documentation of the class itself, not the methods.

I thought adding parent = S7::S7_object to my new_class() call might fix it, but same problem.

hadley commented 12 months ago

Ok, I opened a separate issue for that problem: https://github.com/RConsortium/S7/issues/356. I'd suggest just ignoring it for now; there's nothing that you can do about it — it's just used to indicate that the arguments are optional, because if not supplied the properties will be filled in with their default values.