Skip to content

Commit

Permalink
update news and description
Browse files Browse the repository at this point in the history
+ version bump for Bioc
+ remove some unnecessary whitespace from some R files
  • Loading branch information
grlloyd committed Nov 29, 2023
1 parent fcb8b2d commit 10eda8c
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 162 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: struct
Type: Package
Title: Statistics in R Using Class-based Templates
Version: 1.15.1
Version: 1.15.2
Authors@R: c(
person(
c("Gavin","Rhys"),
Expand Down
10 changes: 9 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Changes 1.15.2
+ add ellipsis to model methods

Changes 1.15.1
+ remove duplicates when using param_ids for objects with inherited params
+ set check.names = FALSE in DatasetExperiment

Changes 1.7.1
+ fix as.code generic
+ improve as.code for all objects
Expand All @@ -11,6 +18,7 @@ Changes in 1.5.2
Changes in 1.1.2
+ improved 'show' output for objects
+ allow ANY for entities

Changes in 1.1.1
+ added citations slot to struct classes
+ added corresponding citations method
Expand All @@ -27,7 +35,7 @@ Changes in 0.99.10
+ add 'signature' input to struct_obj_method

Changes in 0.99.9
+ subsetting of iterators with a single model now converts to a model sequence
+ subsetting of iterators with a single model now converts to a model sequence
with 1 step

Changes in 0.99.8
Expand Down
66 changes: 35 additions & 31 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' @rdname param_obj
setGeneric("param_obj",function(obj,name)standardGeneric("param_obj"))

#' @rdname param_obj
#' @rdname param_obj
#' @export
setGeneric("param_obj<-",function(obj,name,value)standardGeneric("param_obj<-"))

Expand Down Expand Up @@ -77,14 +77,14 @@ setGeneric("param_name",function(obj,name)standardGeneric("param_name"))
#' @examples
#' M = example_model()
#' L = param_list(M)
#'
#'
#' M = example_model()
#' param_list(M) = list('value_1' = 15,'value_2' = 20)
#' @export
#' @rdname param_list
setGeneric("param_list",function(obj)standardGeneric("param_list"))

#' @rdname param_list
#' @rdname param_list
#' @export
setGeneric("param_list<-",function(obj,value)standardGeneric("param_list<-"))

Expand All @@ -98,15 +98,15 @@ setGeneric("param_list<-",function(obj,value)standardGeneric("param_list<-"))
#' @examples
#' M = example_model()
#' param_value(M,'value_1')
#'
#'
#' M = example_model()
#' param_value(M,'value_1') = 0.95
#'
#'
#' @export
#' @rdname param_value
setGeneric("param_value",function(obj,name)standardGeneric("param_value"))

#' @rdname param_value
#' @rdname param_value
#' @export
setGeneric("param_value<-",
function(obj,name,value)standardGeneric("param_value<-"))
Expand Down Expand Up @@ -234,7 +234,7 @@ setGeneric("output_list<-",function(obj,value)standardGeneric("output_list<-"))
#' type as an input.
#'
#' @param obj An object derived from the struct_class object
#' @param ret A string indicating whether a list of objects ('obj') or a list of chart
#' @param ret A string indicating whether a list of objects ('obj') or a list of chart
#' names ('char') is returned. 'char' is default.
#' @return list of chart names, or a list of chart objects
#' @examples
Expand All @@ -248,8 +248,8 @@ setGeneric("chart_names",function(obj,ret='char')standardGeneric("chart_names"))
#' chart_plot
#'
#' Plots a chart object
#'
#' The optional optional inputs depend on the input object/chart, but might
#'
#' The optional optional inputs depend on the input object/chart, but might
#' include an additional dataset object or a second model object, for example.
#' @param obj A chart object
#' @param dobj An object derived from struct_class
Expand All @@ -273,54 +273,58 @@ setGeneric("chart_plot",function(obj, dobj, ...)standardGeneric("chart_plot"))
#' Applies a method to the input dataset
#' @param M a `method` object
#' @param D another object used by the first
#' @param ... other optional inputs
#' @return Returns a modified method object
#' @rdname model_apply
#' @examples
#' M = example_model()
#' M = model_apply(M,iris_DatasetExperiment())
#' @export
setGeneric("model_apply",function(M,D)standardGeneric("model_apply"))
setGeneric("model_apply",function(M,D,...)standardGeneric("model_apply"))


#' Train a model
#'
#' Trains a model using the input dataset
#' @param M a model object
#' @param D a dataset object
#' @param ... other optional inputs
#' @return Returns a modified model object
#' @rdname train
#' @examples
#' M = example_model()
#' M = model_train(M,iris_DatasetExperiment())
#' @export
setGeneric("model_train",function(M,D)standardGeneric("model_train"))
setGeneric("model_train",function(M,D,...)standardGeneric("model_train"))

#' Model prediction
#'
#' Apply a model using the input dataset. Assumes the model is trained
#' first.
#' @param M a model object
#' @param D a dataset object
#' @param ... other optional inputs
#' @return Returns a modified model object
#' @rdname predict
#' @examples
#' M = example_model()
#' M = model_predict(M,iris_DatasetExperiment())
#' @export
setGeneric("model_predict",function(M,D)standardGeneric("model_predict"))
setGeneric("model_predict",function(M,D,...)standardGeneric("model_predict"))

#' Reverse preprocessing
#'
#' Reverse the effect of a preprocessing step on a dataset_
#' @param M a model object
#' @param D a dataset object
#' @param ... other optional inputs
#' @return Returns a modified dataset object
#' @rdname model_reverse
#' @examples
#' M = example_model()
#' D = model_reverse(M,iris_DatasetExperiment())
#' @export
setGeneric("model_reverse",function(M,D)standardGeneric("model_reverse"))
setGeneric("model_reverse",function(M,D,...)standardGeneric("model_reverse"))

#' Predicted output name
#'
Expand All @@ -347,16 +351,16 @@ setGeneric("predicted_name<-",

#' Sequence input
#'
#' get/set the input parameter replaced by the output of the previous model in
#' get/set the input parameter replaced by the output of the previous model in
#' a model sequence. Default is "data" which passes the output as the data input
#' for methods such as \code{model_train} and \code{model_apply}.
#' @param M a model object
#' @param value name of an output for this model
#' @return
#' \describe{
#' \item{\code{seq_in}}{returns the name of the input parameter replaced
#' \item{\code{seq_in}}{returns the name of the input parameter replaced
#' when used in a model sequence}
#' \item{\code{seq_in<-}}{sets the name of the input parameter replaced
#' \item{\code{seq_in<-}}{sets the name of the input parameter replaced
#' when used in a model sequence}
#' }
#' @rdname seq_in
Expand Down Expand Up @@ -584,8 +588,8 @@ setGeneric("stato_definition",function(obj)standardGeneric("stato_definition"))
setGeneric("stato_summary",function(obj)standardGeneric("stato_summary"))

#' Convert a DatasetExperiment to a SummarizedExperiment
#'
#' Converts a DatasetExperiment to SummarizedExperiment. The assay data is
#'
#' Converts a DatasetExperiment to SummarizedExperiment. The assay data is
#' transposed, and colData and rowData switched to match. struct specific
#' slots such as "name" and "description" are stored in the metaData.
#' @param obj a DatasetExperiment object
Expand All @@ -594,8 +598,8 @@ setGeneric("stato_summary",function(obj)standardGeneric("stato_summary"))
setGeneric("as.SummarizedExperiment",function(obj)standardGeneric("as.SummarizedExperiment"))

#' Convert a SummarizedExperiment to DatasetExperiment
#'
#' Converts a SummarizedExperiment to DatasetExperiment. The assay data is
#'
#' Converts a SummarizedExperiment to DatasetExperiment. The assay data is
#' transposed, and colData and rowData switched to match. struct specific
#' slots such as "name" and "description" are extracted from the metaData.
#' @param obj a SummarizedExperiment object
Expand All @@ -604,9 +608,9 @@ setGeneric("as.SummarizedExperiment",function(obj)standardGeneric("as.Summarized
setGeneric("as.DatasetExperiment",function(obj)standardGeneric("as.DatasetExperiment"))

#' Convert to code
#'
#'
#' Prints a block of code that can be used to replicate the input object.
#'
#'
#' @param M a struct model, model_seq or iterator object
#' @param start text prepended to the code. Default is "M = "
#' @param mode "compact" will use the least amount of lines, "expanded" will
Expand All @@ -616,15 +620,15 @@ setGeneric("as.DatasetExperiment",function(obj)standardGeneric("as.DatasetExperi
#' @return A string of code to reproduce the input object.
#' @export
#' @rdname as.code
#' @examples
#' @examples
#' M = example_model(value_1 = 10)
#' as.code(M)
setGeneric('as.code',function(M,start='M = ',mode='compact',quiet=FALSE)standardGeneric("as.code"))

#' convert to data.frame
#'
#' Most often used with univariate statistics to gather all the different outputs in a consistent format.
#'
#'
#' @param M a struct object
#' @param ... other inputs passed through this function
#' @return a data.frame containing outputs from an object
Expand All @@ -633,14 +637,14 @@ setGeneric("as_data_frame",function(M,...)standardGeneric("as_data_frame"))


#' Citations for an object
#'
#'
#' All \code{struct} objects have a "citations" slot, which is a list of
#' references in bibtex format. The \code{citations} method gathers
#' citations from an object and all \code{struct} objects that it inherits to generate
#' a complete list.
#' @param obj a struct object
#' @return a character array of citations
#' @examples
#' @examples
#' D = iris_DatasetExperiment()
#' D$citations # the list specifically defined for this object
#' citations(D) # the list for this object and all inherited ones
Expand All @@ -649,30 +653,30 @@ setGeneric("as_data_frame",function(M,...)standardGeneric("as_data_frame"))
setGeneric("citations",function(obj)standardGeneric("citations"))

#' Libraries for an object
#'
#'
#' All \code{struct} objects have a "libraries" slot, which is a character array of
#' libraries required to use the object. The \code{libraries} method gathers
#' libraries from an object and all \code{struct} objects that it inherits to generate
#' a complete list.
#' @param obj a struct object
#' @return a character array of R packages needed by the object
#' @examples
#' @examples
#' M = example_model()
#' libraries(M)
#' @rdname libraries
#' @export
setGeneric("libraries",function(obj)standardGeneric("libraries"))

#' Ontology for an object
#'
#'
#' All \code{struct} objects have an "ontology" slot, which is a list of
#' ontology items for the object. The \code{ontology} method gathers
#' ontology items from an object and all \code{struct} objects that it inherits to generate
#' a complete list.
#' @param obj a struct object
#' @param cache a named list of ontology_terms for offline use. Terms from the cache are search
#' @param cache a named list of ontology_terms for offline use. Terms from the cache are search
#' based on the name of the list items matching the ontology id. If cache=NULL then the OLS API is used to lookup terms.
#' @examples
#' @examples
#' M = example_model()
#' ontology(M,cache=NULL)
#' @rdname ontology
Expand Down
36 changes: 18 additions & 18 deletions R/model_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
#' Also used for preprocessing steps that require application to test sets.
#' not intended to be called directly, this class should be inherited to provide
#' functionality for method-specific classes.
#'
#'
#' @section \code{predicted} slot:
#' The "predicted" slot is a slots for use by users to control the flow of model
#' sequences. The \code{predicted()} function is used to return a default output and
#' from a model. Typically it is a DatasetExperiment object that is passed directly
#' into the next model in a sequence as the data for that model.
#'
#'
#' @section \code{seq_in} slot:
#' In a sequence of models (see model_seq) the "predicted" slot is connected to the
#' In a sequence of models (see model_seq) the "predicted" slot is connected to the
#' DatasetExperiment input of the next model. \code{seq_in} can be used to control
#' flow and connect the "predicted" output to the input parameter of the next model.
#' Default is the keyword 'data', and can otherwise be replaced by any input slot
#' from the model. The slot \code{seq_fcn} can be used to apply a transformation to
#' Default is the keyword 'data', and can otherwise be replaced by any input slot
#' from the model. The slot \code{seq_fcn} can be used to apply a transformation to
#' the output before it is used as an input. This allows you to e.g. convert between types,
#' extract a single column from a data.frame etc.
#'
#'
#'
#'
#' @export model
#' @param M A struct model object
#' @param D A DatasetExperiment object
#' @param value The value to assign
#' @param value The value to assign
#' @param predicted The name of an output slot to return when using \code{predicted()} (see details)
#' @param seq_in the name of an output slot to connect with the "predicted" output
#' @param seq_in the name of an output slot to connect with the "predicted" output
#' of another model (see details)
#' @param seq_fcn a function to apply to seq_in before inputting into the next model.
#' @param seq_fcn a function to apply to seq_in before inputting into the next model.
#' Typically used to extract a single column, or convert from factor to char etc.
#' @include generics.R parameter_class.R output_class.R
#' @examples
Expand Down Expand Up @@ -144,12 +144,12 @@ setMethod(f = 'predicted',
if (is.null(predicted_name(M))) {
warning('"predicted" is set to NULL')
return(NA)

}
# we can try to return the slot
return(output_value(M,predicted_name(M)))
}

)

#' @rdname model
Expand All @@ -158,16 +158,16 @@ setMethod(f = 'predicted',
#' D = DatasetExperiment()
#' M = example_model()
#' seq_in(M) = 'data'
#' @return the id of the input parameter to be replaced by the \code{predicted}
#' output of the previous model in a model sequence. Reserved keyword 'data'
#' means that the input data used by \code{model_train}, \code{model_apply} etc is used.
#' \code{seq_in = 'data'} is the default setting.
#' @return the id of the input parameter to be replaced by the \code{predicted}
#' output of the previous model in a model sequence. Reserved keyword 'data'
#' means that the input data used by \code{model_train}, \code{model_apply} etc is used.
#' \code{seq_in = 'data'} is the default setting.
setMethod(f = 'seq_in',
signature = c('model'),
definition = function(M) {
return(M@seq_in)
}

)

#' @rdname model
Expand Down Expand Up @@ -242,7 +242,7 @@ setMethod(f = "show",
.DollarNames.struct_class(x,pattern)
}

#' @export
#' @export
#' @rdname autocompletion
setMethod('.DollarNames','model',.DollarNames.model)

Loading

0 comments on commit 10eda8c

Please sign in to comment.