You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
openxlsx2:: wb_add_data_table() in openxlsx2 v0.6 consistently produces the error 'list' object cannot be coerced to type 'logical' when I ask it to add a dataframe with a logical column to a worksheet in a workbook object. Here is my example:
library(openxlsx2)
library(tidyverse)
df<- tribble(
~a_number, ~a_string, ~a_date, ~a_boolean,
1234, "hello", "2023-01-01", FALSE,
4321, "world", "2023-04-01", TRUE
)
# works
wb_workbook() %>%
wb_add_worksheet() %>%
wb_add_data_table(x=df %>% mutate(a_boolean= as.character(a_boolean)))
# fails
wb_workbook() %>%
wb_add_worksheet() %>%
wb_add_data_table(x=df)
#> Error in write_data2(wb = wb, sheet = sheet, data = x, name = name, colNames = colNames, : 'list' object cannot be coerced to type 'logical'
It does not complain about numerics, dates, or strings, but it chokes on logicals.
The text was updated successfully, but these errors were encountered:
pbchase
changed the title
openxlsx2:: wb_add_data_table() will not accept logical columns in the x dataframeopenxlsx2::wb_add_data_table() will not accept logical columns in the x dataframe
Apr 11, 2023
This appears to be some third party issue. Not sure what the tibble logical is, but it is not our issue. Maybe you can have a look @jmbarbone , I do not really do tidyverse stuff. Maybe we need some if (inherits("tbl", x)) x <- as.data.frame(x) if we want to tibble?
library(openxlsx2)
library(tibble)
df<-data.frame(
a_number= c(1234, 4321),
a_string= c("hello", "world"),
a_date= as.Date(c("2023-01-01", "2023-04-01")),
a_boolean= c(FALSE, TRUE)
)
wb<- wb_workbook() %>%
wb_add_worksheet() %>%
wb_add_data_table(x=df)
# same as in the example above. a_date is type character.tbl<-tibble::tribble(
~a_number, ~a_string, ~a_date, ~a_boolean,
1234, "hello", "2023-01-01", FALSE,
4321, "world", "2023-04-01", TRUE
)
wb<- wb_workbook() %>%
wb_add_worksheet() %>%
wb_add_data_table(x= as.data.frame(tbl))
JanMarvin
changed the title
openxlsx2::wb_add_data_table() will not accept logical columns in the x dataframe
[wb_add_data] unable to writetibble logicals
Apr 11, 2023
openxlsx2:: wb_add_data_table()
inopenxlsx2
v0.6 consistently produces the error'list' object cannot be coerced to type 'logical'
when I ask it to add a dataframe with a logical column to a worksheet in a workbook object. Here is my example:Created on 2023-04-11 with reprex v2.0.2
It does not complain about numerics, dates, or strings, but it chokes on logicals.
The text was updated successfully, but these errors were encountered: