Learn R Programming

excel.link (version 0.9.13)

current.graphics: Auxiliary function for export graphics to Microsoft Excel

Description

Auxiliary function for export graphics to Microsoft Excel

Usage

current.graphics(
  type = c("png", "jpeg", "bmp", "tiff"),
  filename = NULL,
  picname = NULL,
  ...
)

Value

Path to file with saved graphics with class attribute 'current.graphics'. If used with argument type than result has attribute temp.file = TRUE.

Arguments

type

file type. Ignored if argument 'filename' provided.

filename

character. filename (or full path) of file with graphics.

picname

character. Picture name in Excel.

...

arguments for internally used dev.copy function

Details

If argument type provided this function will save graphics from windows plotting device to temporary file and return path to this file. Argument filename is intended to transfer plots to Excel from file-based graphics devices (see Examples) or just insert into Excel file with graphics. If argument filename is provided argument type will be ignored and returned value is path to file filename with class attribute 'current.graphics'. So it could be used with expressions such xl[a1] = current.graphics(filename="plot.png"). If picname is provided then picture will be inserted in Excel with this name. If picture picname already exists in Excel it will be deleted. This argument is useful when we need to change old picture in Excel instead of adding new picture. picname will be automatically prepended by "_" to avoid conflicts with Excel range names.

Examples

Run this code

if (FALSE) {
xl.workbook.add()
plot(sin)
xl[a1] = current.graphics()
plot(cos)
cos.plot = current.graphics()
xl.sheet.add()
xl[a1] = list("Cosine plotting",cos.plot,"End of cosine plotting")

# the same thing without graphic windows 
png("1.png")
plot(sin)
dev.off()
sin.plot = current.graphics(filename = "1.png")
png("2.png")
plot(cos)
dev.off()
cos.plot = current.graphics(filename = "2.png")
output = list("Cosine plotting",cos.plot,"Sine plotting",sin.plot)
xl.workbook.add()
xl[a1] = output
}

Run the code above in your browser using DataLab