Skip to content

set_header_label() not possible after separate_header() #593

Description

@namarkus

Hi there, thank for this greate package!
The new separate_header() function is very practical. Unfortunately, it affects the operation of the set_header_label() function.

For layout reasons, I would like to remove the heading of a column. However, this is no longer possible after the separate_header() function:

ft <- flextable(head(iris))
ft <- separate_header(ft, split = '.', fix = TRUE)
ft <- set_header_labels(ft, Species = "")

The label "Species" remains.

If I modify the label first, it works so far:

ft <- flextable(head(iris))
ft <- set_header_labels(ft, Species = "")

The labels "Species" is gone. But after separating header the label "Species" is set again:

ft <- separate_header(ft, split = '.', fix = TRUE)

I can modify header labels that have been separated:

ft <- flextable(head(iris))
ft <- separate_header(ft, split = '.', fix = TRUE)
ft <- set_header_labels(ft, Sepal.Length = "Longeur")

But not the ones that don't have been separated (like "Species" in this example.
I guess set_header_label() should set header labels regardless of whether they have been split or not.

Activity

  1. davidgohel commented on Dec 10, 2023

    @davidgohel
    Owner

    Hello,

    Not really. The separate_header() function will create columns of values starting with the topmost row. Here, "Species" is added to the first row (and last column), then a blank is added.

    The set_header_labels() function will replace the corresponding value in the last row of the header. However, separate_header() has already merged the first and last lines of the last column, and in this case, it's the first value (i.e. first line) that is displayed, while the last line is not.

    You can check this by using merge_none():

    ft <- flextable(head(iris))
    ft <- separate_header(ft, split = '.', fix = TRUE)
    ft <- set_header_labels(ft, Species = "zzz")
    ft <- merge_none(ft)
    ft
    
    Capture d’écran 2023-12-10 à 20 45 30

    In your case, you can use labelizor() instead, it is very handy to raw-replace some labels and quite simple:

    ft <- flextable(head(iris))
    ft <- separate_header(ft, split = '.', fix = TRUE)
    ft <- labelizor(ft, labels = c("Species" = "zzz"), part = "header")
    ft
    
    Capture d’écran 2023-12-10 à 20 47 45
  2. Repository owner locked and limited conversation to collaborators on Dec 10, 2023
  3. converted this issue into a discussion #594 on Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions