accounting for Zhu's coments + major bugfix
diff --git a/R/remove_column.R b/R/remove_column.R
index 4fcfa8b..4e17507 100644
--- a/R/remove_column.R
+++ b/R/remove_column.R
@@ -35,19 +35,36 @@
xml2::xml_text() %>%
stringr::str_trim()
has_rownames <- cell_topleft==""
- if(has_rownames) columns <- columns+1
- body_rows <- xml2::xml_length(kable_tbody)
- for(i in 1:body_rows){
- for(j in columns){
- target_row <- xml2::xml_child(kable_tbody, i)
+ head_row <- xml2::xml_child(kable_thead, 1)
+ ncols <- xml2::xml_length(head_row)
+ body_nrows <- xml2::xml_length(kable_tbody)
+
+ rowspan = matrix(1, nrow = body_nrows, ncol=ncols)
+ for(i in 1:body_nrows){
+ target_row <- xml2::xml_child(kable_tbody, i)
+ target_ncols <- xml2::xml_length(target_row)
+ for(j in 1:target_ncols){
target_cell <- xml2::xml_child(target_row, j)
+ span = as.numeric(xml2::xml_attr(target_cell, "rowspan")) %>% replace_na(0)
+ if(span>0){
+ rowspan[i,j]=1
+ rowspan[i+seq(from=1, to=span-1),j]=0
+ }
+ }
+ }
+
+ for(i in 1:body_nrows){
+ target_row <- xml2::xml_child(kable_tbody, i)
+ for(j in columns){
+ target_cell <- xml2::xml_child(target_row, j)
+ if(rowspan[i,j]==1)
xml2::xml_remove(target_cell)
}
}
- target_row_head <- xml2::xml_child(kable_thead, 1)
+
for(j in columns){
- target_cell_head <- xml2::xml_child(target_row_head, j)
+ target_cell_head <- xml2::xml_child(head_row, j)
xml2::xml_remove(target_cell_head)
}
out <- as_kable_xml(kable_xml)