Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting greek letters from R to Excel

Tags:

r

excel

I want to export strings which includes greek letters to Excel using R.

For example I want to export the below expression:

β00+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.

like image 935
oercim Avatar asked Nov 07 '22 22:11

oercim


1 Answers

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.

like image 113
Kerry Jackson Avatar answered Nov 15 '22 07:11

Kerry Jackson