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

Description Usage Arguments Details Value Examples

View source: R/current.graphics.R

Description

Auxiliary function for export graphics to Microsoft Excel

Usage

1
2
3
4
5
6
current.graphics(
  type = c("png", "jpeg", "bmp", "tiff"),
  filename = NULL,
  picname = NULL,
  ...
)

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.

Value

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
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

## End(Not run)

excel.link documentation built on Nov. 2, 2021, 9:12 a.m.