-
It seems that Workbook class does not work in library(openxlsx2)
df <- data.frame(ID = c(1, 2, 3, 4, 5),
var1 = c('a', 'b', 'c', 'd', 'e'),
var2 = c(1, 1, 0, 0, 1))
wb <- wb_workbook()
# Working
wb$add_worksheet(sheet = 'A')
wb$add_data(sheet = 'A', x = df, na.strings = NULL)
xl_open(wb, interactive = T)
# Not working
wb <- wb_workbook()
wb_add_worksheet(wb, sheet = 'A')
wb_add_data(wb, sheet = 'A', x = df, na.strings = NULL)
#> Error: Can't add data to a workbook with no worksheet.
#> Did you forget to add a worksheet with `wb_add_worksheet()`?
xl_open(wb, interactive = T)
#> Warning: Workbook does not contain any worksheets. A worksheet will be added. Created on 2024-07-18 with reprex v2.1.1
|
Beta Was this translation helpful? Give feedback.
Answered by
JanMarvin
Jul 18, 2024
Replies: 1 comment 4 replies
-
Hi @lz1nwm , you have to assign wrapper functions. library(openxlsx2)
df <- data.frame(ID = c(1, 2, 3, 4, 5),
var1 = c('a', 'b', 'c', 'd', 'e'),
var2 = c(1, 1, 0, 0, 1))
wb <- wb_workbook()
# Working
wb$add_worksheet(sheet = 'A')
wb$add_data(sheet = 'A', x = df, na.strings = NULL)
xl_open(wb, interactive = T)
# Also working
wb <- wb_workbook()
wb <- wb_add_worksheet(wb, sheet = 'A')
wb <- wb_add_data(wb, sheet = 'A', x = df, na.strings = NULL)
xl_open(wb, interactive = T) |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
lz1nwm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @lz1nwm ,
you have to assign wrapper functions.