Dhruv Desai
Dhruv Desai

Reputation: 31

Need some help on R library XLConnect

I am trying to copy graphs and charts from R code to Excel formatted file using XLConnect. I am getting an error "Error: IllegalArgumentException (Java): Name 'Report2' does not exist!" which states that the tab "Report2" does not exist. However, I have created the tab in the code using : "XLConnect::createSheet(wb, name = "Report2")"

When I am able to copy text and tables from R to tab "Report2" but unable to copy charts to the same tab why not able to copy graphs/charts in the same tab.

wb <- loadWorkbook("Data Quality Report2.xls", create = TRUE)
XLConnect::createSheet(wb, name = "Report2")
require(lattice)
png(filename = "earthquake.png", width = 800, height = 600)
devAskNewPage(ask = FALSE)
Depth <- equal.count(quakes$depth, number=8, overlap=.1)
xyplot(lat ~ long | Depth, data = quakes)
update(trellis.last.object(),
       strip = strip.custom(strip.names = TRUE, strip.levels = TRUE),
       par.strip.text = list(cex = 0.75),
       aspect = "iso")
dev.off()

addImage(wb, filename = "earthquake.png", name = "Report2",originalSize = TRUE)

Upvotes: 0

Views: 156

Answers (1)

Martin Studer
Martin Studer

Reputation: 2321

You need to specify the name of a named range (e.g. created via createName) instead of a worksheet name in the call to addImage. See https://www.rdocumentation.org/packages/XLConnect/versions/0.2-15/topics/addImage-methods for a complete example.

Upvotes: 1

Related Questions