Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
+ improve get_description
+ export get_description
+ update as.code to handle case when iterator has default model object
+ rebuild documentation
  • Loading branch information
grlloyd committed Jan 30, 2024
1 parent 9a6d86a commit aa5922c
Show file tree
Hide file tree
Showing 35 changed files with 323 additions and 139 deletions.
5 changes: 3 additions & 2 deletions 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.2
Version: 1.15.3
Authors@R: c(
person(
c("Gavin","Rhys"),
Expand Down Expand Up @@ -49,7 +49,8 @@ Collate:
'resampler_class.R'
'struct.R'
'struct_templates.R'
RoxygenNote: 7.1.2
'zzz.R'
RoxygenNote: 7.2.3
Depends: R (>= 4.0)
Suggests:
testthat,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export("output_value<-")
export("param_list<-")
export("param_obj<-")
export("param_value<-")
export(.struct_class)
export(DatasetExperiment)
export(as.DatasetExperiment)
export(as.SummarizedExperiment)
Expand All @@ -31,6 +32,7 @@ export(enum_stato)
export(example_chart)
export(example_iterator)
export(example_model)
export(get_description)
export(iris_DatasetExperiment)
export(is_output)
export(is_param)
Expand Down
3 changes: 1 addition & 2 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ setGeneric("output_list<-",function(obj,value)standardGeneric("output_list<-"))
#'
#' Returns a list of valid charts for a struct object
#'
#' The chart_names method searches chart objects that specify the input object
#' type as an input.
#' The chart_names method searches for chart objects associated with the unput object.
#'
#' @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
Expand Down
18 changes: 10 additions & 8 deletions R/iterator_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ setMethod(f = 'show',
signature = c('iterator'),
definition = function(object) {
callNextMethod()

if (is(models(object),'model_seq')) {
cat('models: ','a model_seq with ', length(models(object)),' steps\n',sep='')
} else {
Expand All @@ -251,9 +251,11 @@ setMethod(f = 'as.code',
definition = function(M,start='M = ',mode='compact',quiet=FALSE) {
str=.as_code(M,start,mode)
# get models
m=models(M)
# if iterator then multiply
str=paste0(str,' * \n')
m = models(M)
# if iterator then multiply, if not default model
if (class(m)[1]!='model') {
str=paste0(str,' * \n')
}
if (is(m,'model_seq') & length(m) > 1) {
if (mode=='expanded') {
str=paste0(str,paste0(paste0(rep(' ',nchar(start)),collapse=''),'(\n'))
Expand All @@ -266,14 +268,14 @@ setMethod(f = 'as.code',
}

str=paste0(str,')')
} else {
} else if (class(m)[1]!='model') {
str=paste0(str,as.code(m,start=paste0(rep(' ',nchar(start)),collapse=''),mode,quiet=TRUE))
}

if (!quiet){
cat(str)
}

invisible(str)
}
)
Expand All @@ -288,7 +290,7 @@ setMethod(f = 'as.code',
.DollarNames.struct_class(x,pattern)
}

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

18 changes: 9 additions & 9 deletions R/output_class.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @include generics.R struct_class.R
#'
#' @describeIn output_obj
#' @rdname output_obj
#' @export
setMethod(f = "output_obj",
signature = c("struct_class","character"),
Expand All @@ -10,7 +10,7 @@ setMethod(f = "output_obj",
}
)

#' @describeIn output_obj
#' @rdname output_obj
#' @export
#' @return the modified object
setMethod(f = "output_obj<-",
Expand All @@ -24,7 +24,7 @@ setMethod(f = "output_obj<-",
}
)

#' @describeIn is_output
#' @rdname is_output
#' @export
setMethod(f = "is_output",
signature = c("struct_class"),
Expand All @@ -38,7 +38,7 @@ setMethod(f = "is_output",
}
)

#' @describeIn output_ids
#' @rdname output_ids
#' @export
setMethod(f = "output_ids",
signature = c("struct_class"),
Expand All @@ -62,7 +62,7 @@ setMethod(f = "output_ids",
}
)

#' @describeIn output_name
#' @rdname output_name
#' @export
setMethod(f = "output_name",
signature = c("struct_class",'character'),
Expand All @@ -79,7 +79,7 @@ setMethod(f = "output_name",
}
)

#' @describeIn output_list
#' @rdname output_list
#' @export
setMethod(f = 'output_list',
signature = c('struct_class'),
Expand All @@ -93,7 +93,7 @@ setMethod(f = 'output_list',
}
)

#' @describeIn output_list
#' @rdname output_list
#' @export
setMethod(f = 'output_list<-',
signature = c('struct_class','list'),
Expand All @@ -106,7 +106,7 @@ setMethod(f = 'output_list<-',
}
)

#' @describeIn output_value
#' @rdname output_value
#' @export
setMethod(f = "output_value",
signature = c("struct_class","character"),
Expand All @@ -125,7 +125,7 @@ setMethod(f = "output_value",
)


#' @describeIn output_value
#' @rdname output_value
#' @export
setMethod(f = "output_value<-",
signature = c("struct_class","character"),
Expand Down
14 changes: 7 additions & 7 deletions R/parameter_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ setMethod(f = "param_obj",


#' @export
#' @describeIn is_param
#' @rdname is_param
setMethod(f = "is_param",
signature = c("struct_class"),
definition = function(obj,name) {
Expand All @@ -39,7 +39,7 @@ setMethod(f = "is_param",
)

#' @export
#' @describeIn param_ids
#' @rdname param_ids
setMethod(f = "param_ids",
signature = c("struct_class"),
definition = function(obj) {
Expand All @@ -65,7 +65,7 @@ setMethod(f = "param_ids",


#' @export
#' @describeIn param_name
#' @rdname param_name
setMethod(f = "param_name",
signature = c("struct_class",'character'),
definition = function(obj,name) {
Expand All @@ -82,7 +82,7 @@ setMethod(f = "param_name",
)

#' @export
#' @describeIn param_list
#' @rdname param_list
setMethod(f = 'param_list',
signature = c('struct_class'),
definition = function(obj) {
Expand All @@ -96,7 +96,7 @@ setMethod(f = 'param_list',
)

#' @export
#' @describeIn param_list
#' @rdname param_list
setMethod(f = 'param_list<-',
signature = c('struct_class','list'),
definition = function(obj,value) {
Expand All @@ -109,7 +109,7 @@ setMethod(f = 'param_list<-',
)

#' @export
#' @describeIn param_value
#' @rdname param_value
setMethod(f = "param_value",
signature = c("struct_class","character"),
definition = function(obj,name) {
Expand All @@ -128,7 +128,7 @@ setMethod(f = "param_value",
)

#' @export
#' @describeIn param_value
#' @rdname param_value
setMethod(f = "param_value<-",
signature = c("struct_class","character","ANY"),
definition = function(obj,name,value) {
Expand Down
25 changes: 18 additions & 7 deletions R/struct_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ setMethod(f = "$<-",
}
)

#' @describeIn chart_names
#' @export
#' @rdname chart_names
setMethod(f = "chart_names",
signature = c("struct_class"),
definition = function(obj,ret = 'char') {
Expand Down Expand Up @@ -647,7 +647,7 @@ setMethod('.DollarNames','struct_class',.DollarNames.struct_class)
setMethod(f = 'as.code',
signature = c('struct_class'),
definition = function(M,start = 'M = ',mode = 'compact',quiet=FALSE) {
str=.as_code(M,start,mode)
str=struct:::.as_code(M,start,mode)

if (!quiet) {
cat(str)
Expand All @@ -664,9 +664,9 @@ setMethod(f = 'as.code',
if (!(mode %in% c('compact','neat','expanded','full'))) {
stop(paste0('unknown option "', mode , '" for as.code()'))
}
str=start
str = start
# model object name
str=paste0(str,class(M)[1],'(')
str = paste0(str,class(M)[1],'(')

# parameters
P = param_ids(M)
Expand All @@ -679,17 +679,24 @@ setMethod(f = 'as.code',
}
# add predicted if its not the default
if (is(M,'model')) {
N=new_struct(class(M)[1])
N = new_struct(class(M)[1])

if (length(predicted_name(N))==0) {
N@predicted='cake'
N@predicted='not specified'
}
if (length(predicted_name(M))==0) {
M@predicted='not specified'
}

if (predicted_name(N) != predicted_name(M) | mode=='full') {
P=c(P,'predicted')
}
}

if (mode != "compact") {
if ((mode=='neat' | mode=='expanded') & length(P)==0) {
str=paste0(str)
indent=nchar(start)+2
} else if (mode != "compact") {
str=paste0(str,'\n')
indent=nchar(start)+2
} else {
Expand Down Expand Up @@ -753,5 +760,9 @@ setMethod(f = 'as.code',
}
}

if (length(P)==0) {
str=paste0(str,')')
}

return(str)
}
Loading

0 comments on commit aa5922c

Please sign in to comment.