The flextable
help details describes adding new headers as manually typing each existing header name against each new header name, like this:
library(flextable)
ft_1 <- regulartable(head(iris))
ft_1 <- set_header_labels(ft_1, Sepal.Length = "SL",
Sepal.Width = "SW", Petal.Length = "PL",
Petal.Width = "PW"
)
ft_1
How can I just add all new header names from a character string such as
(names2<-c('SL','SW','PL','PW','SPECIES'))
[1] "SL" "SW" "PL" "PW" "SPECIES"
?
So far I have managed a very hacky solution:
names(names2)<-names(ft_1$header$dataset[1,])
ft_1$header$dataset[1,]<-names2