I want to export strings which includes greek letters to Excel using R.
For example I want to export the below expression:
β0=α0+1
I am using XLConnectJars and XLConnect libraries for exporting expressions from R to Excel.
Is there any way to export such expression to export from R to Excel?
For example the below code creates an excel file named "example" to my desktop. That file has an "Expression" sheet and, in that sheet, below expression is printed into the B3 cell:
B0=A0+1
library(XLConnectJars)
library(XLConnect)
wb<-loadWorkbook("data.xlsx", create = TRUE)
createSheet(wb,"Expression")
writeWorksheet(wb,"B0=A0+1", "Expression",startRow = 3,startCol = 2,header=FALSE)
saveWorkbook(wb, file="C:/Users/ozgur/Desktop/example.xlsx")
I want the same thing, but with Greek letters.
I will be very glad for any help? Thanks a lot.
You can do this using unicode characters for the expression for any Greek letters. In the example code below, I also changed the 0 to a subscript 0 using unicode. For this particular expression Beta is Unicode U+03B2, which in R is written as "\U03B2".
library(XLConnectJars)
library(XLConnect)
wb<-loadWorkbook("data.xlsx", create = TRUE)
createSheet(wb,"Expression")
ex <- "\U03B2\U2080=\U03B1\U2080+1"
writeWorksheet(wb,ex, "Expression",startRow = 3,startCol = 2,header=FALSE)
saveWorkbook(wb, file=paste0(Sys.getenv(c("USERPROFILE")),"\\Desktop\\example.xlsx"))
I also used the Sys.getenv to make the saving to the desktop more generalized than a specific user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With