Learn R Programming

officer (version 0.6.8)

body_add_img: Add an image in a 'Word' document

Description

add an image into an rdocx object.

Usage

body_add_img(x, src, style = NULL, width, height, pos = "after", unit = "in")

Arguments

x

an rdocx object

src

image filename, the basename of the file must not contain any blank.

style

paragraph style

width, height

image size in units expressed by the unit argument. Defaults to "in"ches.

pos

where to add the new element relative to the cursor, one of "after", "before", "on".

unit

One of the following units in which the width and height arguments are expressed: "in", "cm" or "mm".

See Also

Other functions for adding content: body_add_blocks(), body_add_break(), body_add_caption(), body_add_docx(), body_add_fpar(), body_add_gg(), body_add_par(), body_add_plot(), body_add_table(), body_add_toc()

Examples

Run this code
doc <- read_docx()

img.file <- file.path(R.home("doc"), "html", "logo.jpg")
if (file.exists(img.file)) {
  doc <- body_add_img(x = doc, src = img.file, height = 1.06, width = 1.39)

  # Set the unit in which the width and height arguments are expressed
  doc <- body_add_img(
    x = doc, src = img.file,
    height = 2.69, width = 3.53,
    unit = "cm"
  )
}

print(doc, target = tempfile(fileext = ".docx"))

Run the code above in your browser using DataLab