I added a small example to demonstrate the issue
library("readxl")
library("openxlsx")
df <- data.frame(QN=1, ST = "String", EL=cbind(list(c("Var1", "Var2"))), BL=FALSE)
cat(paste0("\nQ=", as.numeric(df$QN[[1]])))
cat(paste0("\nST=", as.character(df$ST[[1]])))
cat(paste0("\nEL=", as.character(df$EL[[1]])))
cat(paste0("\nBL=", as.logical(df$BL[[1]])))
wb <- createWorkbook("TEST")
addWorksheet(wb, "Data")
writeData(wb, sheet = 1, df)
saveWorkbook(wb, file = "Test.xlsx", overwrite = TRUE)
df2 <- read_excel(sheet = 1, "Test.xlsx")
cat(paste0("\n\nQ2=", as.numeric(df2$QN[[1]])))
cat(paste0("\nST2=", as.character(df2$ST[[1]])))
cat(paste0("\nEL2=", as.character(df2$EL[[1]])))
cat(paste0("\nBL2=", as.logical(df2$BL[[1]])))
Outputs looks like this
Q=1
ST=String
EL=Var1
EL=Var2
BL=FALSE
Q2=1
ST2=String
EL2=Var1, Var2
BL2=FALSE
When I view the data frame using view(df), I see this:
c("Var1", "Var2") for EL
When I view the second date frame, I see this:
Var1, Var2 for EL
Notice the difference between EL and EL2. I want EL2 to match EL.
--- ORIGINAL QUESTION --- I have a simple data frame that looks like this (I'll list just one element):
cElementNames
c("Roles_1", "Roles_2", "Roles_3")
I save the data frame to Excel using this code:
writeData(wb, sheet = iSheet, df, startCol = 1, startRow = 1)
The column looks like this in the Excel file: Roles_1, Roles_2, Roles_3
I read the Excel file back into a data.frame using this code:
df <- read_excel(sheet = 1, ExcelFile)
The element now looks like this: "Roles_1, Roles_2, Roles_3"
and is not usable in my code.
I am using the data.frame to hold configuration options so that I can generate a report. I would rather read the configuration information from Excel than hard code it in my code.
Since I am new at this, I'll take any advice I can get.
Thanks