Skip to content

Commit

Permalink
Merge pull request #93 from hsloot/feat/show-methods
Browse files Browse the repository at this point in the history
[feat] add `show`-methods
  • Loading branch information
hsloot authored May 29, 2021
2 parents 106d973 + 8927402 commit a6d9ac3
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 12 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Collate:
'RcppExports.R'
'allClass-S4.R'
'allInitialize-S4.R'
'allShow-S4.R'
'allValidity-S4.R'
'catch-routine-registration.R'
'levyDensity-S4.R'
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ exportMethods(exIntensities)
exportMethods(exQMatrix)
exportMethods(intensities)
exportMethods(levyDensity)
exportMethods(show)
exportMethods(stieltjesDensity)
exportMethods(uexIntensities)
exportMethods(valueOf)
Expand All @@ -59,12 +60,15 @@ importFrom(checkmate,check_numeric)
importFrom(checkmate,qassert)
importFrom(checkmate,qtest)
importFrom(methods,callNextMethod)
importFrom(methods,classLabel)
importFrom(methods,new)
importFrom(methods,setClass)
importFrom(methods,setGeneric)
importFrom(methods,setMethod)
importFrom(methods,setValidity)
importFrom(methods,show)
importFrom(methods,validObject)
importFrom(stats,integrate)
importFrom(stats,pgamma)
importFrom(utils,capture.output)
useDynLib(rmo, .registration = TRUE)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Fix implementation of initializers and validity methods. In particular, `validObject` can now
be called with the argument `test = TRUE` without causing an error.
- Add show method for `BernsteinFunction`-classes.

# rmo 0.5.2

Expand Down
2 changes: 1 addition & 1 deletion R/allClass-S4.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @importFrom methods new setClass setValidity setGeneric setMethod validObject
#' callNextMethod
#' callNextMethod show classLabel
NULL

#' Virtual Class \code{BernsteinFunction} for Bernstein Functions
Expand Down
192 changes: 192 additions & 0 deletions R/allShow-S4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#' @importFrom utils capture.output
#' @include allClass-S4.R
NULL

#' @describeIn LinearBernsteinFunction-class Display the object.
#' @aliases show,LinearBernsteinFunction-method
#'
#' @export
setMethod("show", "LinearBernsteinFunction",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat(sprintf("- scale: %s\n", format(object@scale)))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})

#' @describeIn ConstantBernsteinFunction-class Display the object.
#' @aliases show,ConstantBernsteinFunction-method
#'
#' @export
setMethod("show", "ConstantBernsteinFunction",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat(sprintf("- constant: %s\n", format(object@constant)))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})

#' @describeIn ScaledBernsteinFunction-class Display the object.
#' @aliases show,ScaledBernsteinFunction-method
#'
#' @export
setMethod("show", "ScaledBernsteinFunction",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat(sprintf("- scale: %s\n", format(object@scale)))
cat("- original:\n")
writeLines(
paste0("\t", capture.output(show(object@original))))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})

#' @describeIn SumOfBernsteinFunctions-class Display the object.
#' @aliases show,SumOfBernsteinFunctions-method
#'
#' @export
setMethod("show", "SumOfBernsteinFunctions",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat("- first:\n")
writeLines(
paste0("\t", capture.output(show(object@first))))
cat("- second:\n")
writeLines(
paste0("\t", capture.output(show(object@second))))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})

#' @describeIn CompositeScaledBernsteinFunction-class Display the object.
#' @aliases show,CompositeScaledBernsteinFunction-method
#'
#' @export
setMethod("show", "CompositeScaledBernsteinFunction",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat(sprintf("- cscale: %s\n", format(object@cscale)))
cat("- original:\n")
writeLines(
paste0("\t", capture.output(show(object@original))))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})

#' @describeIn PoissonBernsteinFunction-class Display the object.
#' @aliases show,PoissonBernsteinFunction-method
#'
#' @export
setMethod("show", "PoissonBernsteinFunction",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat(sprintf("- lambda: %s\n", format(object@lambda)))
cat(sprintf("- eta: %s\n", format(object@eta)))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})

#' @describeIn AlphaStableBernsteinFunction-class Display the object.
#' @aliases show,AlphaStableBernsteinFunction-method
#'
#' @export
setMethod("show", "AlphaStableBernsteinFunction",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat(sprintf("- alpha: %s\n", format(object@alpha)))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})

#' @describeIn InverseGaussianBernsteinFunction-class Display the object.
#' @aliases show,InverseGaussianBernsteinFunction-method
#'
#' @export
setMethod("show", "InverseGaussianBernsteinFunction",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat(sprintf("- eta: %s\n", format(object@eta)))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})

#' @describeIn ExponentialBernsteinFunction-class Display the object.
#' @aliases show,ExponentialBernsteinFunction-method
#'
#' @export
setMethod("show", "ExponentialBernsteinFunction",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat(sprintf("- lambda: %s\n", format(object@lambda)))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})

#' @describeIn GammaBernsteinFunction-class Display the object.
#' @aliases show,GammaBernsteinFunction-method
#'
#' @export
setMethod("show", "GammaBernsteinFunction",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat(sprintf("- a: %s\n", format(object@a)))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})

#' @describeIn ParetoBernsteinFunction-class Display the object.
#' @aliases show,ParetoBernsteinFunction-method
#'
#' @export
setMethod("show", "ParetoBernsteinFunction",
function(object) {
cat(sprintf("An object of class %s\n", classLabel(class(object))))
if (isTRUE(validObject(object, test = TRUE))) {
cat(sprintf("- alpha: %s\n", format(object@alpha)))
cat(sprintf("- x0: %s\n", format(object@x0)))
} else {
cat("\t (invalid or not initialized)\n")
}

invisible(NULL)
})
7 changes: 6 additions & 1 deletion man/AlphaStableBernsteinFunction-class.Rd

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

7 changes: 6 additions & 1 deletion man/CompositeScaledBernsteinFunction-class.Rd

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

7 changes: 6 additions & 1 deletion man/ConstantBernsteinFunction-class.Rd

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

7 changes: 6 additions & 1 deletion man/ExponentialBernsteinFunction-class.Rd

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

7 changes: 6 additions & 1 deletion man/GammaBernsteinFunction-class.Rd

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

Loading

0 comments on commit a6d9ac3

Please sign in to comment.