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

xlsx::write.xlsx() crashes on tibble with 2+ rows and row.names = F parameter #208

Open
asd-tm opened this issue Jul 3, 2024 · 2 comments
Labels

Comments

@asd-tm
Copy link

asd-tm commented Jul 3, 2024

The issue has been reported at StackOverflow. When I call xlsx::write.xlsx() on a tibble with 2+ rows it crashes:

df <- structure(list(`region name` = c("Reg 1", "Reg 2"), 
                     `value` = c(1.38755717255717, 1.26297588082289)), 
                row.names = c(NA, -2L), 
                class = c("tbl_df", "tbl", "data.frame")) 

xlsx::write.xlsx(df, file = "myfilename.xlsx", row.names = F)

and returns:

Error in if (is.na(value)) { : the condition has length > 1

1st option
If I call the same script setting default row.names = T it executes properly but adds an unneeded column with row number.

xlsx::write.xlsx(df, file = "myfilename.xlsx", 
    row.names = T) # I can skip the parameter

enter image description here

2nd option
If I subset only one row from the tibble the script executes entirely as expected.

xlsx::write.xlsx(df[1, ], file = "myfilename.xlsx", row.names = F)

enter image description here

3rd option
If I convert data to data frame it executes without an error but modifies column names due to data.frame restrictions:

xlsx::write.xlsx(data.frame(df), file = "myfilename.xlsx", row.names = F)

enter image description here

Is it a bug in xlsx::write.xlsx() or I can do something with it?

@bwu62
Copy link

bwu62 commented Jul 12, 2024

Just ran into this myself and it turns out converting to data frame first with as.data.frame() fixes the issue. This should be an easy one for the maintainers to fix.

See #120

@colearendt colearendt added the bug label Aug 27, 2024
@colearendt
Copy link
Owner

Thanks for the great reprex y'all! This definitely seems like a pretty straightforward fix!

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

No branches or pull requests

3 participants