Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_header_row produced an error after using delete_column() #676

Open
ifendo opened this issue Feb 23, 2025 · 2 comments
Open

add_header_row produced an error after using delete_column() #676

ifendo opened this issue Feb 23, 2025 · 2 comments

Comments

@ifendo
Copy link

ifendo commented Feb 23, 2025

Hi,

Thank you for developing the flextable package.

For my use case, I need to dynamically remove a column using the delete_columns() function and then add a custom header row with column spans to the resulting table. However, I am encountering issues when attempting this. Here's a minimal reproducible example:

library(flextable)

# Sample data
df <- data.frame(
  a = c(1, 2, 3),
  b = c(4, 5, 6),
  c = c(7, 8, 9)
)

# Create flextable
df_flex <- df |> flextable::flextable()

# Delete a column
df2 <- df_flex |> flextable::delete_columns("b")

# Add a column span header, it produced an error
df2 <- df2 |> flextable::add_header_row(values = c("x"), colwidths = 2)

I would like to know:

  • Is it possible to add a header row with column spans after deleting a column?
  • If not, is there a recommended workaround to achieve this behavior?

Thank you for your time and support!

@ifendo
Copy link
Author

ifendo commented Feb 23, 2025

and attached my session info for reference:

R version 4.2.3 (2023-03-15)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS 14.7.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10             knitr_1.48              fontquiver_0.2.1        xml2_1.3.4              uuid_1.1-0              R6_2.5.1                ragg_1.2.5              rlang_1.1.0            
 [9] fastmap_1.2.0           fontBitstreamVera_0.1.1 highr_0.11              tools_4.2.3             grid_4.2.3              data.table_1.14.8       xfun_0.48               cli_3.6.1              
[17] htmltools_0.5.8.1       systemfonts_1.1.0       askpass_1.1             openssl_2.0.6           digest_0.6.31           lifecycle_1.0.3         textshaping_0.3.6       zip_2.3.0              
[25] officer_0.6.7.005       evaluate_0.21           flextable_0.9.8.003     rmarkdown_2.28          compiler_4.2.3          gdtools_0.4.1           fontLiberation_0.1.0   

@ifendo
Copy link
Author

ifendo commented Feb 23, 2025

after deleting the b column using delete_columns(), I noticed we have:

Image

I felt like df2$header$dataset is not expected(it did not delete column b), but I am not quite sure thought. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant