Skip to content

Commit

Permalink
move around imports
Browse files Browse the repository at this point in the history
  • Loading branch information
shajoezhu committed Aug 21, 2024
1 parent b600402 commit d6967a8
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 31 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ Imports:
checkmate (>= 2.1.0),
grid,
htmltools (>= 0.5.3),
lifecycle (>= 0.2.0)
lifecycle (>= 0.2.0),
stringi (>= 1.6)
Suggests:
dplyr (>= 1.0.9),
gt (>= 0.10.0),
huxtable (>= 2.0.0),
knitr (>= 1.42),
r2rtf (>= 0.3.2),
rmarkdown (>= 2.23),
stringi (>= 1.6),
testthat (>= 3.0.4),
withr (>= 2.0.0)
VignetteBuilder:
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ importFrom(htmltools,tagList)
importFrom(htmltools,tags)
importFrom(lifecycle,deprecated)
importFrom(stats,na.omit)
importFrom(stringi,stri_detect)
importFrom(stringi,stri_replace)
importFrom(stringi,stri_sub)
importFrom(stringi,stri_wrap)
importFrom(tools,file_ext)
importFrom(utils,capture.output)
importFrom(utils,head)
Expand Down
22 changes: 12 additions & 10 deletions R/matrix_form.R
Original file line number Diff line number Diff line change
Expand Up @@ -895,16 +895,18 @@ mf_has_rlabels <- function(mf) ncol(mf$strings) > mf_ncol(mf)
#' cat(toString(mform))
#'
#' # Advanced test case with label rows
#' library(dplyr)
#' iris_output <- iris %>%
#' group_by(Species) %>%
#' summarize("all obs" = round(mean(Petal.Length), 2)) %>%
#' mutate("DataRow_label" = "Mean")
#' mf <- basic_matrix_form(iris_output,
#' indent_rownames = TRUE,
#' split_labels = "Species", data_labels = "DataRow_label"
#' )
#' cat(toString(mf))
#' if (interactive()) {
#' library(dplyr)
#' iris_output <- iris %>%
#' group_by(Species) %>%
#' summarize("all obs" = round(mean(Petal.Length), 2)) %>%
#' mutate("DataRow_label" = "Mean")
#' mf <- basic_matrix_form(iris_output,
#' indent_rownames = TRUE,
#' split_labels = "Species", data_labels = "DataRow_label"
#' )
#' cat(toString(mf))
#' }
#'
#' @name test_matrix_form
#' @export
Expand Down
1 change: 1 addition & 0 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
#' @importFrom lifecycle deprecated
#' @importFrom stats na.omit
#' @importFrom utils head tail localeToCharset
#' @importFrom stringi stri_detect stri_replace stri_wrap stri_sub
#' @import checkmate
NULL
12 changes: 6 additions & 6 deletions R/tostring.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ do_cell_fnotes_wrap <- function(mat, widths, max_width, tf_wrap, fontspec, expan
correct_indentation <- vapply(seq_along(mf_lgrp), function(xx) {
grouping <- mf_lgrp[xx]
if (nzchar(real_indent[grouping])) {
has_correct_indentation <- stringi::stri_detect(
has_correct_indentation <- stri_detect(
mf_str[xx, 1],
regex = paste0("^", real_indent[grouping])
)
Expand Down Expand Up @@ -434,7 +434,7 @@ do_cell_fnotes_wrap <- function(mat, widths, max_width, tf_wrap, fontspec, expan
# Update also the widths!!
if (do_what[1] == "remove") {
cell_widths_mat[ii, 1] <- cell_widths_mat[ii, 1] - nchar(real_indent[grp])
mfs[ii, 1] <- stringi::stri_replace(lbl_row[ii], "", regex = paste0("^", real_indent[grp]))
mfs[ii, 1] <- stri_replace(lbl_row[ii], "", regex = paste0("^", real_indent[grp]))
} else if (do_what[1] == "add") {
mfs[ii, 1] <- paste0(real_indent[grp], lbl_row[ii])
} else {
Expand Down Expand Up @@ -990,7 +990,7 @@ new_line_warning <- function(str_v) {
#' Wrap a string to a precise width
#'
#' Core wrapping functionality that preserves whitespace. Newline character `"\n"` is not supported
#' by core functionality [stringi::stri_wrap()]. This is usually solved beforehand by [matrix_form()].
#' by core functionality [stri_wrap()]. This is usually solved beforehand by [matrix_form()].
#' If the width is smaller than any large word, these will be truncated after `width` characters. If
#' the split leaves trailing groups of empty spaces, they will be dropped.
#'
Expand All @@ -1002,7 +1002,7 @@ new_line_warning <- function(str_v) {
#' have been split and should be pasted together. This is usually done internally with `"\n"` to update
#' the wrapping along with other internal values.
#'
#' @details Word wrapping happens similarly to [stringi::stri_wrap()] with the following difference: individual
#' @details Word wrapping happens similarly to [stri_wrap()] with the following difference: individual
#' words which are longer than `max_width` are broken up in a way that fits with other word wrapping.
#'
#' @return A string if `str` is one element and if `collapse = NULL`. Otherwise, a list of elements
Expand Down Expand Up @@ -1108,7 +1108,7 @@ wrap_string <- function(str, width, collapse = NULL, fontspec = font_spec()) {
if (w < 1) {
return(str)
}
stringi::stri_wrap(str,
stri_wrap(str,
width = w,
normalize = FALSE, # keeps spaces
simplify = TRUE, # If FALSE makes it a list with str elements
Expand Down Expand Up @@ -1225,7 +1225,7 @@ force_split_words_by <- function(ret, width) {
wrd_i <- ret[ii]
init_v <- seq(1, nchar(wrd_i), by = width)
end_v <- c(init_v[-1] - 1, nchar(wrd_i))
str_v_tmp <- stringi::stri_sub(wrd_i, from = init_v, to = end_v)
str_v_tmp <- stri_sub(wrd_i, from = init_v, to = end_v)
ret_tmp <- c(ret_tmp, str_v_tmp[!grepl("^\\s+$", str_v_tmp) & nzchar(str_v_tmp)])
} else {
ret_tmp <- c(ret_tmp, ret[ii])
Expand Down
22 changes: 12 additions & 10 deletions man/test_matrix_form.Rd

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

4 changes: 2 additions & 2 deletions man/wrap_string.Rd

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

1 change: 0 additions & 1 deletion tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
library(dplyr)
make_basemf_fnotes <- function() {
dfmf <- basic_matrix_form(mtcars)
main_title(dfmf) <- "main title"
Expand Down

0 comments on commit d6967a8

Please sign in to comment.