pander icon indicating copy to clipboard operation
pander copied to clipboard

A column is not split according to `split.cells` when it contains a hyperlink.

Open argx-lcougnaud opened this issue 3 months ago • 2 comments

When a table contains a hyperlink, the split.cells parameter for this column does not seem to be respected:

library(pander)
data <- iris[1:10, ]
data <- cbind(link = "[pander](https://cran.r-project.org/package=pander)", data)
pander::pander(data, 
  split.tables = Inf, 
  split.cells = c(0.1, rep(0.9/(ncol(data)-1), ncol(data)-1))*80
)

Resulting table (Word document created by rmarkdown):

Image

argx-lcougnaud avatar Sep 11 '25 07:09 argx-lcougnaud

I'm not sure if split.cells is doing anything here .. it's supposed to split a cell's text into multiple lines when exceeding the provided threshold at breakpoints. The HTML link doesn't have any break points (whitespace), neither does the other columns. The markdown looks fine, no?

-------------------------------------------------------------------------------------------------------------------------
                        link                           Sepal.Length   Sepal.Width   Petal.Length   Petal.Width   Species 
----------------------------------------------------- -------------- ------------- -------------- ------------- ---------
 [pander](https://cran.r-project.org/package=pander)       5.1            3.5           1.4            0.2       setosa  

 [pander](https://cran.r-project.org/package=pander)       4.9             3            1.4            0.2       setosa  

 [pander](https://cran.r-project.org/package=pander)       4.7            3.2           1.3            0.2       setosa  

 [pander](https://cran.r-project.org/package=pander)       4.6            3.1           1.5            0.2       setosa  

 [pander](https://cran.r-project.org/package=pander)        5             3.6           1.4            0.2       setosa  

 [pander](https://cran.r-project.org/package=pander)       5.4            3.9           1.7            0.4       setosa  

 [pander](https://cran.r-project.org/package=pander)       4.6            3.4           1.4            0.3       setosa  

 [pander](https://cran.r-project.org/package=pander)        5             3.4           1.5            0.2       setosa  

 [pander](https://cran.r-project.org/package=pander)       4.4            2.9           1.4            0.2       setosa  

 [pander](https://cran.r-project.org/package=pander)       4.9            3.1           1.5            0.1       setosa  
-------------------------------------------------------------------------------------------------------------------------

daroczig avatar Sep 11 '25 08:09 daroczig

Hello,

Thanks for the quick reply!

Indeed, the code seems to do what is expected as there is no space in the column containing the link.

So, re-phrasing my question: is there a way to decrease the width of the column containing the link in the example below?

data <- data.frame(
  short = c("short1", "short2"), 
  link = rep("[pander](https://cran.r-project.org/package=pander)", 2), 
  long = c("this is a very long test that would need to have a large column associated to it", "this is a another very long test that would need to have the same large column associated to it")
)
          
pander(data, split.cells = c(10, 10, 80), split.table = Inf)

Result in Word:

Image

argx-lcougnaud avatar Sep 11 '25 10:09 argx-lcougnaud