@@ -47,23 +47,23 @@ gentlg_single <- function(huxme = NULL,
4747 stop(" 'title_file' file must have columns: 'TABLE ID',
4848 'IDENTIFIER', and 'TEXT'" )
4949 }
50- title_df <- title_df % > %
50+ title_df <- title_df | >
5151 filter(`TABLE ID` == file )
5252
5353 if (is.null(title ) && nrow(title_df ) > 0 ) {
54- title <- title_df % > %
55- filter(str_detect(IDENTIFIER , regex(" title" , ignore_case = TRUE ))) % > %
54+ title <- title_df | >
55+ filter(str_detect(IDENTIFIER , regex(" title" , ignore_case = TRUE ))) | >
5656 extract2(" TEXT" )
5757 if (length(title ) == 0 ) {
5858 title <- NULL
5959 }
6060 }
6161 if (is.null(footers ) && nrow(title_df ) > 0 ) {
62- footers <- title_df % > %
62+ footers <- title_df | >
6363 filter(str_detect(
6464 IDENTIFIER ,
6565 regex(" ^footnote" , ignore_case = TRUE )
66- )) % > %
66+ )) | >
6767 extract2(" TEXT" )
6868 if (length(footers ) == 0 ) {
6969 footers <- NULL
@@ -75,21 +75,21 @@ gentlg_single <- function(huxme = NULL,
7575 cm <- attr(huxme , " column_metadata" )
7676 cm <- cm [, colSums(is.na(cm )) < nrow(cm )]
7777 if (any(str_detect(names(cm ), " span" ))) {
78- colspan <- cm % > %
79- select(starts_with(" span" )) % > %
80- as.list() % > %
78+ colspan <- cm | >
79+ select(starts_with(" span" )) | >
80+ as.list() | >
8181 unname()
8282 colspan <- colspan [! purrr :: map_lgl(colspan , ~ all(is.na(. )))]
83- colspan <- purrr :: map(colspan , ~ c(" " , replace_na_with_blank(. ))) % > %
83+ colspan <- purrr :: map(colspan , ~ c(" " , replace_na_with_blank(. ))) | >
8484 rev()
8585 }
8686 }
8787 if (! is.null(attr(huxme , " column_metadata" )) && is.null(colheader )) {
8888 cm <- attr(huxme , " column_metadata" )
8989 if (" decode" %in% names(cm )) {
90- colheader <- cm % > %
91- select(decode ) % > %
92- unlist() % > %
90+ colheader <- cm | >
91+ select(decode ) | >
92+ unlist() | >
9393 unname()
9494 colheader <- c(" " , colheader )
9595 names(colheader ) <- c(" label" , paste0(" col" , seq_len(nrow(cm ))))
@@ -149,7 +149,7 @@ gentlg_single <- function(huxme = NULL,
149149
150150 # Check if the huxme is blank, this will error out in R < 4
151151 if (ncol(huxme ) > 0 ) {
152- huxme <- huxme % > %
152+ huxme <- huxme | >
153153 select(! c(any_of(" func" ), ends_with(" _ord" )))
154154 }
155155
@@ -332,24 +332,24 @@ gentlg_single <- function(huxme = NULL,
332332 # ############################
333333
334334 .to_html <- function (df ) {
335- list_df <- df % > %
336- as.list() % > %
335+ list_df <- df | >
336+ as.list() | >
337337 lapply(gsub ,
338338 pattern = " (\\ {\\\\ super)(.*?)(\\ })" ,
339339 replacement = " <sup>\\ 2</sup>"
340- ) % > %
340+ ) | >
341341 lapply(gsub ,
342342 pattern = " (\\ {\\\\ sub)(.*?)(\\ })" ,
343343 replacement = " <sub>\\ 2</sub>"
344- ) % > %
345- lapply(gsub , pattern = " \\\\ n" , replacement = " <br/>" ) % > %
344+ ) | >
345+ lapply(gsub , pattern = " \\\\ n" , replacement = " <br/>" ) | >
346346 lapply(gsub , pattern = " \\\\ line" , replacement = " <br/>" )
347347
348348 if (base :: inherits(df , " data.frame" )) {
349- df <- list_df % > %
349+ df <- list_df | >
350350 data.frame (stringsAsFactors = FALSE , check.names = FALSE )
351351 } else if (base :: inherits(df , " character" ) && ! is.null(df )) {
352- df <- list_df % > %
352+ df <- list_df | >
353353 unlist(use.names = FALSE )
354354 }
355355
@@ -429,7 +429,7 @@ gentlg_single <- function(huxme = NULL,
429429 }
430430
431431 if (! is.na(idvars [1 ]) && dim(huxme )[1 ] > = 1 ) {
432- for (i in rev(seq_len(length( idvars ) ))) {
432+ for (i in rev(seq_along( idvars ))) {
433433 less <- idvars [1 : i ]
434434 huxme [duplicated(huxme [, less ]), less ] <- " "
435435 }
@@ -476,9 +476,10 @@ gentlg_single <- function(huxme = NULL,
476476 # ############################
477477 # ## Huxit! ###
478478 # ############################
479+
479480 if (is_format_rtf(format )) {
480481 if (tolower(substr(tlf , 1 , 1 )) %in% c(" t" )) {
481- ht <- huxtable :: as_hux(huxme , add_colnames = TRUE ) % > %
482+ ht <- huxtable :: as_hux(huxme , add_colnames = TRUE ) | >
482483 huxtable :: set_width(value = huxwidth )
483484 if (ncol(ht ) == length(colheader )) {
484485 ht [1 , ] <- colheader
@@ -487,23 +488,25 @@ gentlg_single <- function(huxme = NULL,
487488 " Column header not used; {length(colheader)} column header provided, but data contain {ncol(ht)} columns"
488489 )
489490 }
491+ ht [1 , 1 ] <- replace_lead_whitespaces_ind(ht [1 , 1 ])
490492 ht [1 , ] <- paste0(" \\ keepn\\ trhdr " , ht [1 , ]) # Make repeated treatments on each page
491493 formatindex <- 1
492494 } else if (tolower(substr(tlf , 1 , 1 )) %in% c(" l" )) {
493- ht <- huxtable :: as_hux(huxme , add_colnames = TRUE ) % > %
495+ ht <- huxtable :: as_hux(huxme , add_colnames = TRUE ) | >
494496 huxtable :: set_width(value = huxwidth )
495497 ht [1 , ] <- colheader
498+ ht [1 , 1 ] <- replace_lead_whitespaces_ind(ht [1 , 1 ])
496499 ht [1 , ] <- paste0(" \\ keepn\\ trhdr " , ht [1 , ]) # Make repeated treatments on each page
497500 formatindex <- 1
498501 } else if (tolower(substr(tlf , 1 , 1 )) %in% c(" f" , " g" )) {
499- ht <- huxtable :: as_hux(huxme , add_colnames = FALSE ) % > %
502+ ht <- huxtable :: as_hux(huxme , add_colnames = FALSE ) | >
500503 huxtable :: set_width(value = huxwidth )
501504 } else {
502505 stop(" tlf can have following character values: Table, Listing, Graph, Figure" )
503506 }
504507 } else if (is_format_html(format )) {
505508 if (tolower(substr(tlf , 1 , 1 )) %in% c(" t" )) {
506- ht <- huxtable :: as_hux(huxme , add_colnames = TRUE ) % > %
509+ ht <- huxtable :: as_hux(huxme , add_colnames = TRUE ) | >
507510 huxtable :: set_width(value = huxwidth )
508511 if (ncol(ht ) == length(colheader )) {
509512 ht [1 , ] <- colheader
@@ -515,20 +518,20 @@ gentlg_single <- function(huxme = NULL,
515518
516519 formatindex <- 1
517520 } else if (tolower(substr(tlf , 1 , 1 )) %in% c(" l" )) {
518- ht <- huxtable :: as_hux(huxme , add_colnames = TRUE ) % > %
521+ ht <- huxtable :: as_hux(huxme , add_colnames = TRUE ) | >
519522 huxtable :: set_width(value = huxwidth )
520523 ht [1 , ] <- colheader
521524 formatindex <- 1
522525 } else if (tolower(substr(tlf , 1 , 1 )) %in% c(" f" , " g" )) {
523- ht <- huxtable :: as_hux(huxme , add_colnames = FALSE ) % > %
526+ ht <- huxtable :: as_hux(huxme , add_colnames = FALSE ) | >
524527 huxtable :: set_width(value = huxwidth )
525528 } else {
526529 stop(" tlf can have following character values: Table, Listing, Graph, Figure" )
527530 }
528531 }
529532
530- ht <- ht % > %
531- huxtable :: set_right_padding(value = getOption(" tidytlg.right.padding" )) % > %
533+ ht <- ht | >
534+ huxtable :: set_right_padding(value = getOption(" tidytlg.right.padding" )) | >
532535 huxtable :: set_left_padding(value = getOption(" tidytlg.left.padding" ))
533536
534537 # ############################
@@ -562,15 +565,16 @@ gentlg_single <- function(huxme = NULL,
562565
563566 # ## add row one by one to maintain huxtable structure
564567 if (is_format_rtf(format )) {
565- for (i in rev(seq_len(length(colspan )))) {
568+ for (i in rev(seq_along(colspan ))) {
569+ colspan [[i ]][1 ] <- replace_lead_whitespaces_ind(colspan [[i ]][1 ])
566570 ht <- huxtable :: insert_row(ht , paste0(" \\ keepn\\ trhdr " , colspan [[i ]]),
567571 after = 0 , fill = " "
568- ) % > %
572+ ) | >
569573 huxtable :: set_number_format(row = 1 , col = seq_len(ncol(ht )), value = NA )
570574 }
571575 } else if (is_format_html(format )) {
572576 # ## add row one by one to maintain huxtable structure
573- for (i in rev(seq_len(length( colspan ) ))) {
577+ for (i in rev(seq_along( colspan ))) {
574578 ht <- huxtable :: insert_row(ht , paste0(colspan [[i ]]), after = 0 )
575579 }
576580 }
@@ -612,10 +616,10 @@ gentlg_single <- function(huxme = NULL,
612616
613617 # ## font size
614618 if ((tolower(substr(tlf , 1 , 1 )) %in% " l" )) {
615- ht <- ht % > %
619+ ht <- ht | >
616620 huxtable :: set_font_size(value = getOption(" tidytlg.fontsize.listing" ))
617621 } else {
618- ht <- ht % > %
622+ ht <- ht | >
619623 huxtable :: set_font_size(value = getOption(" tidytlg.fontsize.table" ))
620624 }
621625
@@ -874,8 +878,8 @@ gentlg_single <- function(huxme = NULL,
874878 getOption(" tidytlg.fontsize.table" )
875879 ) / 10
876880
877- ht <- huxtable :: set_top_border(ht , 1 , value = bordervalue ) % > %
878- huxtable :: set_bottom_border(1 , value = bordervalue ) % > %
881+ ht <- huxtable :: set_top_border(ht , 1 , value = bordervalue ) | >
882+ huxtable :: set_bottom_border(1 , value = bordervalue ) | >
879883 huxtable :: set_bottom_border(nrow(ht ), value = bordervalue )
880884 } else if (is_format_html(format )) {
881885 ht [1 , ] <- paste0(" <div style='border-top :1pt solid; border-bottom :1pt solid; '> " , ht [1 , ])
@@ -904,7 +908,7 @@ gentlg_single <- function(huxme = NULL,
904908 font_size = size , border = 0
905909 )
906910 }
907- return ( dsnin )
911+ dsnin
908912 }
909913 } else if (is_format_html(format )) {
910914 add_footer <- function (dsnin , footer , first = FALSE , size = fontsize ) {
@@ -925,7 +929,7 @@ gentlg_single <- function(huxme = NULL,
925929 font_size = size , border = 0
926930 )
927931 }
928- return ( dsnin )
932+ dsnin
929933 }
930934 }
931935
0 commit comments