# NOT RUN {
# get rlogo
img.file <- file.path( Sys.getenv("R_HOME"), "doc", "html", "logo.jpg" )
# tests to use later
has_img <- file.exists( img.file )
has_jpeg <- requireNamespace("jpeg", quietly = TRUE)
has_wmf <- exists("win.metafile")
is_sunos <- tolower(Sys.info()[["sysname"]]) == "sunos"
# create a wmf file if possible
if( has_wmf ){
win.metafile(filename = "image.wmf", width = 5, height = 5 )
barplot( 1:6, col = 2:7)
dev.off()
}
# Image example for MS Word -------
# }
# NOT RUN {
doc <- docx()
if( has_img && has_jpeg ){
dims <- attr( jpeg::readJPEG(img.file), "dim" )
doc <- addImage(doc, img.file, width = dims[2]/72,
height = dims[1]/72)
}
if( has_wmf ){
doc <- addImage(doc, "image.wmf", width = 5, height = 5 )
}
writeDoc( doc, file = "ex_add_image.docx" )
# }
# NOT RUN {
# Image example for MS PowerPoint -------
# }
# NOT RUN {
if( !is_sunos ){
doc <- pptx()
if( has_img && has_jpeg ){
doc <- addSlide( doc, "Title and Content" )
dims <- attr( jpeg::readJPEG(img.file), "dim" )
doc <- addImage(doc, img.file, width = dims[2]/72,
height = dims[1]/72)
}
if( has_wmf ){
doc <- addSlide( doc, "Title and Content" )
doc <- addImage(doc, "image.wmf", width = 5, height = 5 )
}
writeDoc( doc, file = "ex_add_image.pptx" )
}
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab