Skip to content

Commit

Permalink
Apply styler, fix lint (#219)
Browse files Browse the repository at this point in the history
Closes #218
  • Loading branch information
edelarua authored Oct 19, 2023
1 parent 6995290 commit bb14dba
Show file tree
Hide file tree
Showing 20 changed files with 2,383 additions and 2,185 deletions.
1 change: 1 addition & 0 deletions .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ linters: linters_with_defaults(
line_length_linter = line_length_linter(120),
commented_code_linter = NULL,
cyclocomp_linter = NULL,
object_usage_linter = NULL,
object_name_linter = NULL
)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## formatters 0.5.4.9001
* Applied `styler` and resolved package lint. Changed default indentation from 4 spaces to 2.

## formatters 0.5.4
* Fixed a bug in `paginate_to_mpfs()` so that formatting in listings key columns is retained with pagination [`insightsengineering/rlistings#155`](https://github.com/insightsengineering/rlistings/issues/155).
Expand Down
27 changes: 13 additions & 14 deletions R/format_value.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' @importFrom htmltools tags tagList

formats_1d <- c(
Expand Down Expand Up @@ -85,10 +84,7 @@ list_valid_aligns <- function() {
#' @name check_formats
#' @export
is_valid_format <- function(x, stop_otherwise = FALSE) {
is_valid <- is.null(x) ||
(length(x) == 1 &&
(is.function(x) ||
x %in% unlist(list_valid_format_labels())))
is_valid <- is.null(x) || (length(x) == 1 && (is.function(x) || x %in% unlist(list_valid_format_labels())))

if (stop_otherwise && !is_valid) {
stop("format needs to be a format label, sprintf_format object, a function, or NULL")
Expand All @@ -107,12 +103,12 @@ is_valid_format <- function(x, stop_otherwise = FALSE) {
#' @name check_formats
#' @export
check_aligns <- function(algn) {
if(anyNA(algn))
stop("Got missing-value for text alignment.")
invalid <- setdiff(algn, list_valid_aligns())
if(length(invalid) > 0) {
stop("Unsupported text-alignment(s): ",
paste(invalid, collapse = ", "))
if (anyNA(algn)) {
stop("Got missing-value for text alignment.")
}
invalid <- setdiff(algn, list_valid_aligns())
if (length(invalid) > 0) {
stop("Unsupported text-alignment(s): ", paste(invalid, collapse = ", "))
}
invisible(TRUE)
}
Expand Down Expand Up @@ -432,9 +428,12 @@ format_value <- function(x, format = NULL, output = c("ascii", "html"), na_str =
setClassUnion("FormatSpec", c("NULL", "character", "function", "list"))
setClassUnion("characterOrNULL", c("NULL", "character"))
setClass("fmt_config",
slots = c(format = "FormatSpec",
format_na_str = "characterOrNULL",
align = "characterOrNULL"))
slots = c(
format = "FormatSpec",
format_na_str = "characterOrNULL",
align = "characterOrNULL"
)
)

#' Format Configuration
#'
Expand Down
15 changes: 7 additions & 8 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,18 @@ setMethod("make_row_df", "MatrixPrintForm", function(tt, colwidths = NULL, visib
sibpos = NA_integer_,
nsibs = NA_integer_,
max_width = NULL) {
stop("make_row_df can be used only on {rtables} table objects, and not on `matrix_form`-",
"generated objects (MatrixPrintForm).")
stop(
"make_row_df can be used only on {rtables} table objects, and not on `matrix_form`-",
"generated objects (MatrixPrintForm)."
)
})
## nocov end


#' Transform `rtable` to a list of matrices which can be used for outputting
#'
#' Although `rtables` are represented as a tree data structure when outputting the table to ASCII or HTML it is useful to
#' map the `rtable` to an in between state with the formatted cells in a matrix form.
#' Although `rtables` are represented as a tree data structure when outputting the table to ASCII or HTML it is
#' useful to map the `rtable` to an in between state with the formatted cells in a matrix form.
#'
#' @param obj ANY. Object to be transformed into a ready-to-render form (a `MatrixPrintForm` object)
#' @param indent_rownames logical(1), if TRUE the column with the row names in the `strings` matrix of has indented row
Expand Down Expand Up @@ -189,10 +191,7 @@ setMethod(
if (length(x) == 0) {
0L
} else {
sum(unlist(vapply(x, nlines, NA_integer_,
colwidths = colwidths,
max_width = max_width
)))
sum(unlist(vapply(x, nlines, NA_integer_, colwidths = colwidths, max_width = max_width)))
}
}
)
Expand Down
4 changes: 0 additions & 4 deletions R/labels.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@




#' Return an object with a label attribute
#'
#' @param x an object
Expand Down
Loading

0 comments on commit bb14dba

Please sign in to comment.