Skip to content

Commit

Permalink
styler
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Dec 12, 2024
1 parent 6fb7edf commit 67b3a09
Show file tree
Hide file tree
Showing 58 changed files with 2,173 additions and 2,045 deletions.
172 changes: 91 additions & 81 deletions R/class.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,48 @@ swap_class <- function(x, new_class) {
setClassUnion("NULLorCharacter", c("NULL", "character"))

#' tinytable S4 class
#'
#'
#' @keywords internal
#' @export
setClass(
Class = "tinytable",
slots = representation(
table_dataframe = "data.frame",
table_string = "character",
data = "data.frame",
caption = "character",
width = "numeric",
width_cols = "numeric",
notes = "list",
theme = "list",
placement = "character",
body = "character",
nrow = "numeric",
ncol = "numeric",
nhead = "numeric",
ngroupi = "numeric",
ngroupj = "numeric",
group_i_idx = "numeric",
names = "NULLorCharacter",
output = "character",
output_dir = "character",
id = "character",
bootstrap_class = "character",
bootstrap_css_rule = "character",
css = "data.frame",
style = "data.frame",
lazy_format = "list",
lazy_group = "list",
lazy_style = "list",
lazy_plot = "list",
lazy_finalize = "list",
lazy_theme = "list",
portable = "logical"
)
Class = "tinytable",
slots = representation(
table_dataframe = "data.frame",
table_string = "character",
data = "data.frame",
caption = "character",
width = "numeric",
width_cols = "numeric",
notes = "list",
theme = "list",
placement = "character",
body = "character",
nrow = "numeric",
ncol = "numeric",
nhead = "numeric",
ngroupi = "numeric",
ngroupj = "numeric",
group_i_idx = "numeric",
names = "NULLorCharacter",
output = "character",
output_dir = "character",
id = "character",
bootstrap_class = "character",
bootstrap_css_rule = "character",
css = "data.frame",
style = "data.frame",
lazy_format = "list",
lazy_group = "list",
lazy_style = "list",
lazy_plot = "list",
lazy_finalize = "list",
lazy_theme = "list",
portable = "logical"
)
)

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("initialize", "tinytable", function(
Expand Down Expand Up @@ -95,85 +95,97 @@ setMethod("initialize", "tinytable", function(
})

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("nrow", "tinytable", function(x) return(x@nrow))
setMethod("nrow", "tinytable", function(x) {
return(x@nrow)
})

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("ncol", "tinytable", function(x) return(x@ncol))
setMethod("ncol", "tinytable", function(x) {
return(x@ncol)
})

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
#' @export
setMethod("colnames", "tinytable", function(x) return(x@names))
setMethod("colnames", "tinytable", function(x) {
return(x@names)
})

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
#' @export
setMethod("names", "tinytable", function(x) return(x@names))
setMethod("names", "tinytable", function(x) {
return(x@names)
})

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
#' @export
setReplaceMethod("colnames",
signature = "tinytable",
definition = function(x, value) {
# Issue #306
if (length(value) == 0) value <- NULL
if (!is.null(value)) {
assert_character(value, len = length(x@names))
} else {
if (x@nhead == 1) x@nhead <- 0
}
x@names <- value
return(x)
}
signature = "tinytable",
definition = function(x, value) {
# Issue #306
if (length(value) == 0) value <- NULL
if (!is.null(value)) {
assert_character(value, len = length(x@names))
} else {
if (x@nhead == 1) x@nhead <- 0
}
x@names <- value
return(x)
}
)

#' Method for a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
#' @export
setReplaceMethod("names",
signature = "tinytable",
definition = function(x, value) {
# Issue #306
if (length(value) == 0) value <- NULL
if (!is.null(value)) {
assert_character(value, len = length(x@names))
} else {
if (x@nhead == 1) x@nhead <- 0
}
x@names <- value
return(x)
}
signature = "tinytable",
definition = function(x, value) {
# Issue #306
if (length(value) == 0) value <- NULL
if (!is.null(value)) {
assert_character(value, len = length(x@names))
} else {
if (x@nhead == 1) x@nhead <- 0
}
x@names <- value
return(x)
}
)

#' Dimensions a tinytable S4 object
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("dim", "tinytable", function(x) return(c(x@nrow, x@ncol)))
setMethod("dim", "tinytable", function(x) {
return(c(x@nrow, x@ncol))
})

#' Column names of a tinytable
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("names", "tinytable", function(x) return(x@names))
setMethod("names", "tinytable", function(x) {
return(x@names)
})

#' Convert a tinytable S4 object to a string
#'
#'
#' @inheritParams tt
#' @keywords internal
setMethod("as.character", "tinytable", function(x) {
Expand All @@ -188,7 +200,7 @@ setClass("tinytable_grid", contains = "tinytable")
setClass("tinytable_dataframe", contains = "tinytable")

#' Apply style settings to a tinytable
#'
#'
#' @inheritParams tt
#' @keywords internal
setGeneric(
Expand All @@ -197,7 +209,7 @@ setGeneric(
)

#' Apply group settings to a tinytable
#'
#'
#' @inheritParams tt
#' @keywords internal
setGeneric(
Expand All @@ -206,7 +218,7 @@ setGeneric(
)

#' Apply group settings to a tinytable
#'
#'
#' @inheritParams tt
#' @keywords internal
setGeneric(
Expand All @@ -215,12 +227,10 @@ setGeneric(
)

#' Apply final settings to a tinytable
#'
#'
#' @inheritParams tt
#' @keywords internal
setGeneric(
name = "finalize",
def = function(x, ...) standardGeneric("finalize")
)


Loading

0 comments on commit 67b3a09

Please sign in to comment.