Flextable 忽略 R 中的单元格宽度参数
我在 R 中有一个数据框,我已将其转换为 Flextable。看起来不错,但我需要手动设置列宽。我尝试了多种方法来实现这一目标,但到目前为止还没有成功。我发现特别奇怪的是,当我运行 dim(myflextable) 来查看尺寸时,返回的值是我设置的值,但 Flextable 本身没有这些尺寸。任何见解将不胜感激。
数据框+库
library(dplyr)
library(flextable)
library(officer)
extractionWS <- structure(list(Sample = c(12740L, 13231L, 13232L, 13233L, 13234L),
Full.name = c("Method Negative Control In Vitro Extraction 600 uL RLT-TCEP 23",
"G-A12-T5_7H9tw_co2_0-05_p0-8_b0-8_48h_tube49",
"G-A12-T4_7H9tw_co2_0-05_p0-8_b0-8_h0-1_96h_tube90",
"G-A13-T3_7H9tw_co2_0-05_untx_192h_tube71",
"G-A12-T5_7H9tw_co2_0-05_p0-8_b0-8_opc0-00195_48h_tube77"),
Providing.lab.key = c(NA, "VOS22_00349",
"VOS22_00290",
"VOS22_00675",
"VOS22_00377"),
kitshelf = c("", "", "", "", ""),
kitbox = c(8, 8, 8, 8, 8),
kitpos = c("A1", "A2", "A3", "A4", "A5"),
extractdate = c("", "", "", "", ""),
concentration = c("", "", "", "", ""),
rnashelf = c("", "", "", "", ""),
rnabox = c("", "", "", "", ""),
rnapos = c("", "", "", "", ""),
comment = c("", "", "", "", "")),
class = "data.frame", row.names = c(NA, -5L))
extractionWS <- extractionWS %>%
setNames(c("WL Number", 'Full Name', "Providing Lab Key",
"Kit Shelf", "Kit Box", "Kit Position",
"Extraction Date", "RNA Conc. (ng/ul)",
"Extracted RNA Shelf", "Extracted RNA Box","Extracted RNA Position", "Comment"))
弹性格式尝试
#Create flextable
worksheet <- flextable(extractionWS)
#font style
worksheet <- bold(worksheet, bold = TRUE, part="header")
worksheet <- align(worksheet, align = "center", part = "all")
worksheet <- colformat_num(worksheet, big.mark="")
#border
border.outer = fp_border(color="black", width=2.5)
border.horizontal = fp_border(color="black", width=1.5)
border.vertical = fp_border(color="black", width=1.5)
worksheet <- border_outer(worksheet, border=border.outer, part="all")
worksheet <- border_inner_h(worksheet, part="all", border = border.horizontal)
worksheet <- border_inner_v(worksheet, part="all", border = border.vertical)
#Set fontsize
worksheet <- fontsize(worksheet, size = 12, part = "body")
worksheet <- fontsize(worksheet, j = 2, size = 8, part = "body")
#dimensions
worksheet <- width(worksheet, 12, width = 6)
暗淡(工作表)输出 - 指示我成功更改了列宽:
$widths
WL.num Full.name Providing.lab.key kitshelf kitbox
0.75 0.75 0.75 0.75 0.75
kitpos extractdate concentration rnashelf rnabox
0.75 0.75 0.75 0.75 0.75
rnapos comment Kit Position
0.75 6.00 0.75
但这没有反映在表中:
抱歉,如果我遗漏了一些明显的内容,我已经花了很多时间在这个简单的事情上并浏览了文档,但一直无法找到解决方案。
I have a dataframe in R that I have converted to a Flextable. It looks okay, but I need to manually set the column widths. I've tried to accomplish this several ways and so far have not been successful. What I find especially odd is that when I run dim(myflextable) to look at the dimensions, the returned values are what I've set them as but the Flextable itself does not have those dimensions. Any insight would be appreciated.
dataframe + libraries
library(dplyr)
library(flextable)
library(officer)
extractionWS <- structure(list(Sample = c(12740L, 13231L, 13232L, 13233L, 13234L),
Full.name = c("Method Negative Control In Vitro Extraction 600 uL RLT-TCEP 23",
"G-A12-T5_7H9tw_co2_0-05_p0-8_b0-8_48h_tube49",
"G-A12-T4_7H9tw_co2_0-05_p0-8_b0-8_h0-1_96h_tube90",
"G-A13-T3_7H9tw_co2_0-05_untx_192h_tube71",
"G-A12-T5_7H9tw_co2_0-05_p0-8_b0-8_opc0-00195_48h_tube77"),
Providing.lab.key = c(NA, "VOS22_00349",
"VOS22_00290",
"VOS22_00675",
"VOS22_00377"),
kitshelf = c("", "", "", "", ""),
kitbox = c(8, 8, 8, 8, 8),
kitpos = c("A1", "A2", "A3", "A4", "A5"),
extractdate = c("", "", "", "", ""),
concentration = c("", "", "", "", ""),
rnashelf = c("", "", "", "", ""),
rnabox = c("", "", "", "", ""),
rnapos = c("", "", "", "", ""),
comment = c("", "", "", "", "")),
class = "data.frame", row.names = c(NA, -5L))
extractionWS <- extractionWS %>%
setNames(c("WL Number", 'Full Name', "Providing Lab Key",
"Kit Shelf", "Kit Box", "Kit Position",
"Extraction Date", "RNA Conc. (ng/ul)",
"Extracted RNA Shelf", "Extracted RNA Box","Extracted RNA Position", "Comment"))
flextable format attempt
#Create flextable
worksheet <- flextable(extractionWS)
#font style
worksheet <- bold(worksheet, bold = TRUE, part="header")
worksheet <- align(worksheet, align = "center", part = "all")
worksheet <- colformat_num(worksheet, big.mark="")
#border
border.outer = fp_border(color="black", width=2.5)
border.horizontal = fp_border(color="black", width=1.5)
border.vertical = fp_border(color="black", width=1.5)
worksheet <- border_outer(worksheet, border=border.outer, part="all")
worksheet <- border_inner_h(worksheet, part="all", border = border.horizontal)
worksheet <- border_inner_v(worksheet, part="all", border = border.vertical)
#Set fontsize
worksheet <- fontsize(worksheet, size = 12, part = "body")
worksheet <- fontsize(worksheet, j = 2, size = 8, part = "body")
#dimensions
worksheet <- width(worksheet, 12, width = 6)
dim(worksheet) output - indicates I successfully changed the column width:
$widths
WL.num Full.name Providing.lab.key kitshelf kitbox
0.75 0.75 0.75 0.75 0.75
kitpos extractdate concentration rnashelf rnabox
0.75 0.75 0.75 0.75 0.75
rnapos comment Kit Position
0.75 6.00 0.75
But this is not reflected in the table:
Sorry if I'm missing something obvious, I've spent a lot of time on this simple thing and gone over the documentation but haven't been able to find a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论