Retrieves elements from a slide as a list of typed element objects, with optional filtering by element type and/or spatial region.
Usage
get_elements(slide, type = NULL, within = NULL, contains = c("any", "all"))Arguments
- slide
A
slideobject (fromon_slide_id(),on_slide_number(), etc.).- type
Optional character vector of element types to keep. Valid values:
"text","image","chart","table","shape","unknown". IfNULL(default) all element types are returned.- within
Optional. Either a
slide_positionobject (a rectangular query region) or a numeric vector of length 2c(top, left)in inches (a single point). For a point, elements whose bounding box contains the point are returned. IfNULL(default), no spatial filtering is applied.- contains
One of
"any"(default) or"all". Controls how an element's bounding box is compared to aslide_positionwithinregion:"any": element is kept if it overlaps the region."all": element is kept only if it is fully inside the region.
Ignored when
withinis a point.
Value
A list of element objects (text_element, image_element, etc.).
Returns an empty list if no elements match the filters.
Details
Type filtering (type): Supply one or more of "text", "image",
"chart", "table", "shape", "unknown" to restrict the result to
those element types. Uses element_type() for classification.
Spatial filtering (within / contains): within can be either a
region or a single point.
A
slide_positiondefines a rectangular region. Thecontainsargument then controls strictness:"any"(default): keep elements whose bounding box intersects the region (any overlap)."all": keep elements whose bounding box is fully contained within the region (strict containment).
A length-2 numeric vector
c(top, left)in inches defines a single point. Elements whose bounding box contains that point are returned, andcontainsis ignored.
Rotation is accounted for when computing bounding boxes via
slide_position's bounding_box() computed property.
Examples
if (FALSE) {
ps <- register_presentation(id = "YOUR_PRESENTATION_ID", set_active = FALSE)
slide_obj <- on_slide_number(1, ps)
# All elements
all_els <- get_elements(slide_obj)
# Text elements only
text_els <- get_elements(slide_obj, type = "text")
# Elements overlapping the top-left quadrant
region <- slide_position(top = 0, left = 0, width = 5, height = 2.8)
top_left_els <- get_elements(slide_obj, within = region)
# Elements fully contained within the region
inner_els <- get_elements(slide_obj, within = region, contains = "all")
# Elements covering the point 2" down, 3" from the left
at_point <- get_elements(slide_obj, within = c(2, 3))
}