I have data frames like this:
print_table <- structure(list(run_no = c("031_01", "031_02", "031_04", "031_05",
"031_75", "031_01", "031_02", "031_04", "031_05", "031_75", "031_01",
"031_03", "031_04", "031_05", "031_75"), compound = structure(c(1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L), levels = c("KET",
"HNK", "NKT"), class = "factor"), LQC = list(c(31.36, 30.8),
c(26.48, 26.03), c(28.08, 28), c(29.98, 29.65), 29.98, c(15.06,
15.26), c(13.45, 14.62), c(14.38, 15.35), c(15.61, 15.01),
15.61, c(15.23, 15.85), c(12.71, 14.21), c(13.73, 14.64),
c(14.6, 14.84), 14.6), AQC = list(c(85.51, 82.22), c(75.77,
75.29), c(81.8, 80), c(85.93, 83.02), NULL, c(83.74, 78.02),
c(74.74, 72.75), c(79.26, 77.81), c(82.61, 79.09), NULL,
c(89.32, 82.28), c(79.28, 78.23), c(84.49, 81.21), c(85.5,
85.14), NULL), MQC = list(c(610.08, 617.3), c(577.4, 562.11
), 592.64, c(617.81, 634.02), NULL, c(586.05, 592.87), c(552.92,
565.82), 588.54, c(599.48, 593.91), NULL, c(603.57, 606.09),
c(602.11, 598.24), 602.48, c(632.99, 625.64), NULL), HQC = list(
c(1663.12, 2724.5), c(1515.56, 1491.92), 1577.25, c(1648.55,
1719.57), NULL, c(1632.04, 2877.82), c(1470.51, 1475.84),
1634.41, c(1710.32, 1798.04), NULL, c(1588.98, 2508.34),
c(1500, 1498.12), 1620.83, c(1663.5, 1710.09), NULL), DQC = list(
NULL, c(7890.7, 7564.08, 7434.21), NULL, NULL, NULL, NULL,
c(7829.17, 7563.91, 7395.04), NULL, NULL, NULL, NULL, c(7652.33,
7546.14, 7739.59), NULL, NULL, NULL)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -15L))
I try to render it using gt() both into pdf and word format.
Pdf is for our file; word is to copy paste it to another document (have no choice here – it can’t be as graphic file)
As standard output gt() generates:
What I really need is:
For word it is easy to fix manually (Ctrl +H , to paragraph). But its tedious to do it for many small tables.
Is theree any way to force gt to make those line breaks?
I can pivot this table without nesting.
I have unique id (file_name) for each of those values, but using it create to many empty rows.
Number of entries for different desired cells are from 1 to 5 (or maybe more in the future) and most values comes from different files.
Under one file_name there are values for run-level (levels are xQC) pair for three compounds usually. Some files have data for only two or one compound.
I tried to group by run_no, level and compound and then number each value in group.
This way was better. Less empty rows but stil for each run_no-compound pair I obtained 1 to 5 rows wchich looks messy. Manually joining cells in word is more painfull than changing comma to endline.
I need the same table structure in word and pdf (for regulatory reasons).
I can manually change tables in word but not in pdf.
I could save word as pdf, but there is a catch, our internal reports in pdf have styling that is defined by SOP and I can’t replicate it in Quarto generated .doc (nor can I change it).
Going from .doc to .pdf would require manual styling of every document prior to conversion.
So I’m bit stuck here.
Any ideas?
It might help.
Sample data frame before pivoting (still containing file names – cant share real data it just an example)
rep <- structure(list(data_file = c("031_01_030", "031_01_030", "031_01_030",
"031_01_042", "031_01_042", "031_01_042", "031_01_054", "031_01_054",
"031_01_054", "031_01_066", "031_01_066", "031_01_066", "031_01_078",
"031_01_078", "031_01_078", "031_01_090", "031_01_090", "031_01_090",
"031_01_102", "031_01_102", "031_01_102", "031_01_109", "031_01_109",
"031_01_109", "031_02_026", "031_02_026", "031_02_046", "031_02_046",
"031_02_065", "031_02_065", "031_02_084", "031_02_084", "031_02_102",
"031_02_102", "031_02_104", "031_02_104", "031_02_124", "031_02_124",
"031_02_138", "031_02_138", "031_02_144", "031_02_144", "031_02_162",
"031_02_162", "031_02_163", "031_02_163", "031_03_026", "031_03_046",
"031_03_065", "031_03_084", "031_03_102", "031_03_104", "031_03_124",
"031_03_138", "031_03_144", "031_03_162", "031_03_163", "031_04_030",
"031_04_030", "031_04_030", "031_04_052", "031_04_052", "031_04_052",
"031_04_072", "031_04_072", "031_04_072", "031_04_093", "031_04_093",
"031_04_093", "031_04_115", "031_04_115", "031_04_115", "031_04_137",
"031_04_137", "031_04_137", "031_05_024", "031_05_024", "031_05_024",
"031_05_033", "031_05_033", "031_05_033", "031_05_039", "031_05_039",
"031_05_039", "031_05_046", "031_05_046", "031_05_046", "031_05_052",
"031_05_052", "031_05_052", "031_05_059", "031_05_059", "031_05_059",
"031_05_066", "031_05_066", "031_05_066", "031_05_073", "031_05_073",
"031_05_073", "031_75_024", "031_75_024", "031_75_024"), run_no = c("031_01",
"031_01", "031_01", "031_01", "031_01", "031_01", "031_01", "031_01",
"031_01", "031_01", "031_01", "031_01", "031_01", "031_01", "031_01",
"031_01", "031_01", "031_01", "031_01", "031_01", "031_01", "031_01",
"031_01", "031_01", "031_02", "031_02", "031_02", "031_02", "031_02",
"031_02", "031_02", "031_02", "031_02", "031_02", "031_02", "031_02",
"031_02", "031_02", "031_02", "031_02", "031_02", "031_02", "031_02",
"031_02", "031_02", "031_02", "031_03", "031_03", "031_03", "031_03",
"031_03", "031_03", "031_03", "031_03", "031_03", "031_03", "031_03",
"031_04", "031_04", "031_04", "031_04", "031_04", "031_04", "031_04",
"031_04", "031_04", "031_04", "031_04", "031_04", "031_04", "031_04",
"031_04", "031_04", "031_04", "031_04", "031_05", "031_05", "031_05",
"031_05", "031_05", "031_05", "031_05", "031_05", "031_05", "031_05",
"031_05", "031_05", "031_05", "031_05", "031_05", "031_05", "031_05",
"031_05", "031_05", "031_05", "031_05", "031_05", "031_05", "031_05",
"031_75", "031_75", "031_75"), level = structure(c(1L, 1L, 1L,
2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 1L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 4L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 1L,
1L, 2L, 2L, 5L, 5L, 3L, 3L, 4L, 4L, 5L, 5L, 1L, 2L, 3L, 4L, 5L,
1L, 2L, 5L, 3L, 4L, 5L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L,
4L, 4L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L,
3L, 4L, 4L, 4L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L,
1L, 1L, 1L), levels = c("LQC", "AQC", "MQC", "HQC", "DQC"), class = "factor"),
compound = structure(c(2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L,
2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L,
2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L,
2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L,
2L, 1L, 3L), levels = c("KET", "HNK", "NKT"), class = "factor"),
final = c(15.06, 31.36, 15.23, 83.74, 85.51, 89.32, 586.05,
610.08, 603.57, 1632.04, 1663.12, 1588.98, 15.26, 30.8, 15.85,
78.02, 82.22, 82.28, 592.87, 617.3, 606.09, 2877.82, 2724.5,
2508.34, 13.45, 26.48, 74.74, 75.77, 552.92, 577.4, 1470.51,
1515.56, 7829.17, 7890.7, 14.62, 26.03, 72.75, 75.29, 7563.91,
7564.08, 565.82, 562.11, 1475.84, 1491.92, 7395.04, 7434.21,
12.71, 79.28, 602.11, 1500, 7652.33, 14.21, 78.23, 7546.14,
598.24, 1498.12, 7739.59, 14.38, 28.08, 13.73, 79.26, 81.8,
84.49, 588.54, 592.64, 602.48, 1634.41, 1577.25, 1620.83,
15.35, 28, 14.64, 77.81, 80, 81.21, 15.61, 29.98, 14.6, 82.61,
85.93, 85.5, 599.48, 617.81, 632.99, 1710.32, 1648.55, 1663.5,
15.01, 29.65, 14.84, 79.09, 83.02, 85.14, 593.91, 634.02,
625.64, 1798.04, 1719.57, 1710.09, 15.61, 29.98, 14.6)), row.names = c(NA,
-102L), class = c("tbl_df", "tbl", "data.frame"), na.action = structure(c(`35` = 35L,
`39` = 39L, `43` = 43L, `47` = 47L, `51` = 51L, `55` = 55L, `59` = 59L,
`63` = 63L, `67` = 67L, `71` = 71L, `75` = 75L, `77` = 77L, `78` = 78L,
`80` = 80L, `81` = 81L, `82` = 82L, `84` = 84L, `85` = 85L, `86` = 86L,
`88` = 88L, `89` = 89L, `90` = 90L, `92` = 92L, `93` = 93L, `94` = 94L,
`96` = 96L, `97` = 97L, `98` = 98L, `100` = 100L, `101` = 101L,
`102` = 102L, `104` = 104L, `105` = 105L, `106` = 106L, `108` = 108L,
`109` = 109L, `110` = 110L, `112` = 112L, `113` = 113L, `114` = 114L,
`116` = 116L, `117` = 117L, `118` = 118L, `120` = 120L), class = "omit"))