Search code examples
rflextableofficer

How to name a column " " in officer was able to do it previously in ReporteRs


this is a big problem for me as I need to have un-named column names inside my flextable in officer. This previously worked with the ReporteRs version. But so far haven't been able to do this, tried using the following code:

rename(` ` = col0)

When I run try and create a flextable using this column name I get the following error message: Error in flextable(a) : invalid col_keys, flextable support only syntactic names

data <- head(iris) %>%
  rename(` ` = Sepal.Length)
myft <- regulartable(data)
myft1<- flextable(data)

Note: the regulartable(data) works and the column name is blank. When trying to do this with a flextable however it doesn't work and errors

Is there anyway that I am able to do this with a flextable?

Many thanks in advance


Solution

  • You don't need to modify your data.frame to customize the display. Having names like is risky IHMO. Read https://davidgohel.github.io/flextable/articles/layout.html#manage-headers-and-footers

    library(flextable)
    library(magrittr)
    library(dplyr)
    
    data <- head(iris)
    myft <- regulartable(data) %>% 
      set_header_labels(Sepal.Length = " ")
    
    myft1 <- flextable(data) %>% 
      set_header_labels(Sepal.Length = " ")
    
    myft1