Skip to content

Commit

Permalink
doc: mergelcMethod-related generic docs with other signatures (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
niekdt committed Jan 25, 2024
1 parent 80d6707 commit 608735b
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 90 deletions.
43 changes: 17 additions & 26 deletions R/generics.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#' @name latrend-generics
#' @title Method- and model-specific generics defined by the latrend package
#' @description List of S4 generic methods which have no general use other than supporting
#' functions with signatures of `lcMethod` or `lcModel`.
#' @param object The object.
#' @param method The method.
#' @param data `data.frame`.
#' @param newdata `data.frame` of newdata.
#' @param name Metric name.
#' @param envir `environment`.
#' @param what Parameter.
#' @param cluster Cluster name.
#' @param verbose [R.utils::Verbose].
#' @param ... Arguments.
#' @keywords internal
NULL


# nClusters ####
#' @export
#' @name nClusters
Expand Down Expand Up @@ -127,8 +109,9 @@ setGeneric('clusterTrajectories', function(object, ...) {

# compose ####
#' @export
#' @name latrend-generics
setGeneric('compose', def = function(method, envir, ...) {
#' @name compose
#' @param ... Not used.
setGeneric('compose', function(method, envir, ...) {
newmethod <- standardGeneric('compose')

assert_that(
Expand Down Expand Up @@ -246,7 +229,9 @@ setGeneric('estimationTime', function(object, unit = 'secs', ...) {

# fit ####
#' @export
#' @name latrend-generics
#' @name fit
#' @param ... Not used.
#' @return The fitted object, inheriting from `lcModel`.
setGeneric('fit', function(method, data, envir, verbose, ...) {
dateStart = Sys.time()
start = .tic()
Expand Down Expand Up @@ -544,7 +529,8 @@ setGeneric('plotTrajectories', function(object, ...) standardGeneric('plotTrajec

# postFit ####
#' @export
#' @name latrend-generics
#' @name postFit
#' @param ... Not used.
setGeneric('postFit', function(method, data, model, envir, verbose, ...) {
model <- standardGeneric('postFit')

Expand Down Expand Up @@ -761,7 +747,9 @@ setGeneric('predictPostprob', function(object, newdata = NULL, ...) {

# prepareData ####
#' @export
#' @name latrend-generics
#' @name prepareData
#' @param ... Not used.
#' @return An `environment`.
setGeneric('prepareData', function(method, data, verbose, ...) {
envir <- standardGeneric('prepareData')
assert_that(
Expand All @@ -778,8 +766,8 @@ setGeneric('prepareData', function(method, data, verbose, ...) {

# preFit ####
#' @export
#' @name latrend-generics
#' @aliases preFit-method
#' @name preFit
#' @param ... Not used.
setGeneric('preFit', function(method, data, envir, verbose, ...) {
modelEnv <- standardGeneric('preFit')
assert_that(
Expand Down Expand Up @@ -945,7 +933,10 @@ setGeneric('trajectoryAssignments', function(object, ...) {

# validate ####
#' @export
#' @name latrend-generics
#' @name validate
#' @param ... Not used.
#' @return Either `TRUE` if all validation checks passed,
#' or a `scalar character` containing a description of the failed validation checks.
setGeneric('validate', function(method, data, envir, ...) {
validationResult <- standardGeneric('validate')

Expand Down
13 changes: 5 additions & 8 deletions R/method.R
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ as.data.frame.lcMethod = function(x, ..., eval = TRUE, nullValue = NA, envir = N

#. compose ####
#' @export
#' @name compose
#' @rdname compose
#' @aliases compose,lcMethod-method
#' @title `lcMethod` estimation step: compose an lcMethod object
#' @description Note: this function should not be called directly, as it is part of the `lcMethod` [estimation procedure][lcMethod-estimation].
Expand Down Expand Up @@ -519,7 +519,7 @@ setMethod('compose', 'lcMethod', function(method, envir = NULL) {

# . fit ####
#' @export
#' @name fit
#' @rdname fit
#' @aliases fit,lcMethod-method
#' @title `lcMethod` estimation step: logic for fitting the method to the processed data
#' @description Note: this function should not be called directly, as it is part of the `lcMethod` [estimation procedure][lcMethod-estimation].
Expand All @@ -528,7 +528,6 @@ setMethod('compose', 'lcMethod', function(method, envir = NULL) {
#' The `fit()` function of the `lcMethod` object estimates the model with the evaluated method specification, processed training data, and prepared environment.
#' @inheritParams preFit
#' @param envir The `environment` containing variables generated by [prepareData()] and [preFit()].
#' @return The fitted object inheriting from `lcModel`.
#' @section Implementation:
#' This method should be implemented for all `lcMethod` subclasses.
#'
Expand Down Expand Up @@ -813,7 +812,7 @@ setMethod('names', 'lcMethod', function(x) {


# . preFit ####
#' @name preFit
#' @rdname preFit
#' @aliases preFit,lcMethod-method
#' @title `lcMethod` estimation step: method preparation logic
#' @description Note: this function should not be called directly, as it is part of the `lcMethod` [estimation procedure][lcMethod-estimation].
Expand Down Expand Up @@ -879,7 +878,7 @@ setMethod('prepareData', 'lcMethod', function(method, data, verbose) {


# . postFit ####
#' @name postFit
#' @rdname postFit
#' @aliases postFit,lcMethod-method
#' @title `lcMethod` estimation step: logic for post-processing the fitted lcModel
#' @description Note: this function should not be called directly, as it is part of the `lcMethod` [estimation procedure][lcMethod-estimation].
Expand Down Expand Up @@ -1171,7 +1170,7 @@ setMethod('timeVariable', 'lcMethod', function(object, ...) object$time)

#. validate ####
#' @export
#' @name validate
#' @rdname validate
#' @aliases validate,lcMethod-method
#' @title `lcMethod` estimation step: method argument validation logic
#' @description Note: this function should not be called directly, as it is part of the `lcMethod` [estimation procedure][lcMethod-estimation].
Expand All @@ -1191,8 +1190,6 @@ setMethod('timeVariable', 'lcMethod', function(object, ...) object$time)
#' @param method An object inheriting from `lcMethod` with all its arguments having been evaluated and finalized.
#' @param data A `data.frame` representing the transformed training data.
#' @param ... Not used.
#' @return Either `TRUE` if all validation checks passed,
#' or a `character` containing a description of the failed validation checks.
#' @inheritSection lcMethod-estimation Estimation procedure
#' @section Implementation:
#' An example implementation checking for the existence of specific arguments and type:
Expand Down
15 changes: 11 additions & 4 deletions R/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,20 @@ setMethod('externalMetric', c('lcModels', 'missing'),
setMethod('externalMetric', c('lcModels', 'character'),
function(object, object2 = 'adjustedRand') {
.externalMetricDist.lcModels(object, name = object2)
})
}
)


#' @export
#' @name externalMetric
#' @rdname externalMetric
#' @aliases externalMetric,lcModels,lcModels-method
#' @return For `externalMetric(lcModels, lcModel)`: A named `numeric` vector or `data.frame`
#' containing the computed model metrics.
setMethod('externalMetric', c('lcModels', 'lcModel'), .externalMetric.lcModels)


#' @export
#' @name externalMetric
#' @rdname externalMetric
#' @aliases externalMetric,list,lcModel-method
#' @inheritParams metric
#' @return For `externalMetric(list, lcModel)`: A named `numeric` vector or `data.frame`
Expand All @@ -259,7 +260,8 @@ setMethod('externalMetric', c('list', 'lcModel'),
function(object, object2, name, drop = TRUE) {
models = as.lcModels(object)
.externalMetric.lcModels(models, object2, name, drop = drop)
})
}
)


.metric.lcModels = function(object, name, drop = TRUE) {
Expand Down Expand Up @@ -300,11 +302,13 @@ setMethod('metric', 'list', function(object, name, drop = TRUE) {
.metric.lcModels(as.lcModels(object), name, drop = drop)
})


#' @export
#' @rdname metric
#' @return For `metric(lcModels)`: A `data.frame` with a metric per column.
setMethod('metric', 'lcModels', .metric.lcModels)


#' @export
#' @title Select the lcModel with the lowest metric value
#' @inheritSection lcModels-class Functionality
Expand Down Expand Up @@ -341,6 +345,7 @@ min.lcModels = function(x, name, ...) {
}
}


#' @export
#' @title Select the lcModel with the highest metric value
#' @inheritSection lcModels-class Functionality
Expand Down Expand Up @@ -524,6 +529,7 @@ plotMetric = function(
p
}


#' @export
#' @title Subsetting a lcModels list based on method arguments
#' @inheritSection lcModels-class Functionality
Expand Down Expand Up @@ -568,6 +574,7 @@ subset.lcModels = function(x, subset, drop = FALSE, ...) {
}
}


#' @export
#' @title Print lcModels list concisely
#' @inheritSection lcModels-class Functionality
Expand Down
6 changes: 5 additions & 1 deletion man/compose.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/externalMetric.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions man/fit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/interface-akmedoids.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/interface-flexmix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/interface-funFEM.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/interface-kml.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 3 additions & 40 deletions man/latrend-generics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/lcMethodAkmedoids.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/postFit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 608735b

Please sign in to comment.