First, thanks to Adrian A. Dragulescu, the author of the 'xlsx' package,
for an immensely useful package!  I hope this Email is useful to someone
out there, I thought it may be useful to document.

On Mac OS X 10.6 I had a problem using the package 'xlsx', it could not
color-shade Excel cells.  One fix is to run the Java process in headless
mode.  In the example below, I show how to run rJava in headless mode, and
I also increased the Java memory heap size to 1 Gigabyte (mostly to
demonstrate how to set multiple Java parameters at once.)  Omit or adjust
the heapsize option as needed.  I include a working example.  (I hope!)

################## BEGIN TEST
## The option below is used upon initializing the rJava environment
## and may be placed in an .Renviron or .Rprofile file
options( java.parameters = c("-Djava.awt.headless=true", "-Xmx1g") );

## Once initialized, load the 'xlsx' package:
library(xlsx);

## The example code follows below:
wb <- createWorkbook();
sheet <- createSheet(wb, "Sheet1");
rows  <- createRow(sheet, rowIndex=1);
cell.1 <- createCell(rows, colIndex=1)[[1,1]];
setCellValue(cell.1, "Hello R!");
## The following function 'createCellStyle' fails without the fix on a Mac:
cellStyle1 <- createCellStyle(wb, borderPosition="RIGHT",
                              borderPen="BORDER_DASHED",
fillBackgroundColor="yellow",
                              fillForegroundColor="tomato",
fillPattern="BIG_SPOTS");
setCellStyle(cell.1, cellStyle1);
saveWorkbook(wb, "testExcelWorkbook.xlsx");
################## END TEST

Alternatively, one can manually initialize the Java environment, but you
must do so before loading the 'xlsx' package, like so:

     library(rJava);
     .jinit(parameters=c("-Djava.awt.headless=true", "-Xmx2g") );
     library(xlsx);


Now I can try to create Excel files with multiple worksheets, fancy
cell-shading, and use "freeze panes" on the first row of data!  :-)

-- 
James M. Ward
Computational Biologist and Genome Bioinformaticist
NIEHS Bioinformatics, RTP, NC

	[[alternative HTML version deleted]]

