Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# tidytlg 0.11.0.9000

- Replaced leading whitespaces in header col 1 with left-indentation RTF markup.

# tidytlg 0.11.0

- Fixed RTF landscape tag (#54).
Expand Down
17 changes: 17 additions & 0 deletions R/gentlg_single.R
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs tests as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added unit tests for replace_lead_whitespaces_ind()

Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
is.list(border_fns),
all(vapply(border_fns, is.function, FUN.VALUE = logical(1)))
)
assertthat::assert_that(is.matrix(bottom_borders) || bottom_borders == "old_format")

Check warning on line 30 in R/gentlg_single.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/gentlg_single.R,line=30,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 86 characters.
arglist <- list()
args_to_chk <- names(formals())[names(formals()) != "..."]
purrr::walk(args_to_chk, .f = {
function(x) arglist[[x]] <<- eval(rlang::sym(x))
})
check_gentlg(arglist)

Check warning on line 36 in R/gentlg_single.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/gentlg_single.R,line=36,col=3,[object_usage_linter] no visible global function definition for 'check_gentlg'
if (identical(footers, NA) || length(footers) == 0) {
footers <- NULL
}
Expand All @@ -47,12 +47,12 @@
stop("'title_file' file must have columns: 'TABLE ID',
'IDENTIFIER', and 'TEXT'")
}
title_df <- title_df %>%

Check warning on line 50 in R/gentlg_single.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/gentlg_single.R,line=50,col=26,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.

Check warning on line 50 in R/gentlg_single.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/gentlg_single.R,line=50,col=26,[object_usage_linter] no visible global function definition for '%>%'
filter(`TABLE ID` == file)

Check warning on line 51 in R/gentlg_single.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/gentlg_single.R,line=51,col=14,[object_usage_linter] no visible binding for global variable 'TABLE ID'

if (is.null(title) && nrow(title_df) > 0) {
title <- title_df %>%

Check warning on line 54 in R/gentlg_single.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/gentlg_single.R,line=54,col=25,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.

Check warning on line 54 in R/gentlg_single.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/gentlg_single.R,line=54,col=25,[object_usage_linter] no visible global function definition for '%>%'

Check warning on line 54 in R/gentlg_single.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/gentlg_single.R,line=54,col=25,[object_usage_linter] no visible global function definition for '%>%'
filter(str_detect(IDENTIFIER, regex("title", ignore_case = TRUE))) %>%

Check warning on line 55 in R/gentlg_single.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/gentlg_single.R,line=55,col=27,[object_usage_linter] no visible binding for global variable 'IDENTIFIER'

Check warning on line 55 in R/gentlg_single.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/gentlg_single.R,line=55,col=16,[object_usage_linter] no visible global function definition for 'str_detect'
extract2("TEXT")
if (length(title) == 0) {
title <- NULL
Expand Down Expand Up @@ -476,6 +476,20 @@
#############################
### Huxit! ###
#############################

replace_leading_whitespaces_with_indentation <- function(x) {
# get number of whitespaces at the beginning of column 1 in the header
num_whitespaces <- attr(regexpr("^\\s*", x), "match.length")
# 2 whitespaces represent an indentation of 0.125 inches = 180 twips
# e.g. 4 whitespaces represent a left-indentation of 0.25 inches = 360 twips
num_twips <- num_whitespaces * 90
if (num_twips > 0) {
raw_rtf_markup <- paste0("\\intbl\\li", num_twips, "\\fi0")
x <- paste0(raw_rtf_markup, " ", trimws(x, "left"))
}
return(x)
}

if (is_format_rtf(format)) {
if (tolower(substr(tlf, 1, 1)) %in% c("t")) {
ht <- huxtable::as_hux(huxme, add_colnames = TRUE) %>%
Expand All @@ -487,12 +501,14 @@
"Column header not used; {length(colheader)} column header provided, but data contain {ncol(ht)} columns"
)
}
ht[1, 1] <- replace_leading_whitespaces_with_indentation(ht[1, 1])
ht[1, ] <- paste0("\\keepn\\trhdr ", ht[1, ]) # Make repeated treatments on each page
formatindex <- 1
} else if (tolower(substr(tlf, 1, 1)) %in% c("l")) {
ht <- huxtable::as_hux(huxme, add_colnames = TRUE) %>%
huxtable::set_width(value = huxwidth)
ht[1, ] <- colheader
ht[1, 1] <- replace_leading_whitespaces_with_indentation(ht[1, 1])
ht[1, ] <- paste0("\\keepn\\trhdr ", ht[1, ]) # Make repeated treatments on each page
formatindex <- 1
} else if (tolower(substr(tlf, 1, 1)) %in% c("f", "g")) {
Expand Down Expand Up @@ -563,6 +579,7 @@
### add row one by one to maintain huxtable structure
if (is_format_rtf(format)) {
for (i in rev(seq_len(length(colspan)))) {
colspan[[i]][1] <- replace_leading_whitespaces_with_indentation(colspan[[i]][1])
ht <- huxtable::insert_row(ht, paste0("\\keepn\\trhdr ", colspan[[i]]),
after = 0, fill = ""
) %>%
Expand Down
Loading