Results Elements

Results Elements are the building blocks of a jamovi analysis output. They are R6 objects that jamovi automatically instantiates based on the Results Definition (.r.yaml) of your module.

In your analysis R code, these elements are accessed via self$results. For example, if you have a table named resultsTable defined in your .r.yaml, you can access it in R using:

self$results$resultsTable

The Results Tree

The results of an analysis are organized in a hierarchical structure known as the Results Tree. The root of this tree is self$results (which is itself a Group element).

Elements like Groups and Arrays can contain other elements, allowing you to create complex, nested output structures.

Relationship to YAML

The available elements and their initial configuration (such as titles, visibility, and default settings) are defined in the .r.yaml file. When an analysis is run, jamovi reads this definition and creates the corresponding R6 objects. While you can modify many properties of these objects at runtime (e.g., changing a title or hiding a table), their fundamental structure is determined by the YAML.

Element Types

jamovi provides several types of results elements, each designed for a specific purpose:

ElementDescription
TableThe most common element, used for displaying tabular data, statistics, and coefficients.
ImageUsed for displaying plots and other graphical output.
GroupA container used to group related elements together.
ArrayA dynamic container that can hold multiple instances of the same element type (e.g., a table for each level of a factor).
NoticeUsed for displaying informational messages, warnings, or errors.
PreformattedUsed for displaying raw text output, often from other R packages.
HtmlUsed for displaying custom HTML content.

Common API

All results elements share a common set of properties and methods. These can be accessed using the $ operator.

Properties

name

A string specifying the name of the element as defined in the .r.yaml.

title

A string specifying the title of the element.

visible

A boolean (TRUE or FALSE) indicating whether the element is currently visible in the jamovi results panel.

status

A string indicating the current status of the element. Possible values are:

state

The state object associated with the element, used for caching and performance optimization.

Methods

setTitle(title)

Sets the title of the element.

setVisible(visible)

Sets the visibility of the element.

setStatus(status)

Sets the status of the element.

setError(message)

Sets the element’s status to 'error' and displays the provided error message.

setState(object)

Sets the state object for the element.

Dynamic Creation

While most results elements are defined in the .r.yaml file, they can also be created dynamically in R during the execution of an analysis. This is useful for output structures that depend on the data or for conditional elements like warnings.

Use Cases

Methods

To add a dynamically created element to the results, you can use the insert() method on a Group object.

insert(index, element)

Inserts an element at a specific position within a group.

Example:

notice <- jmvcore::Notice$new(options=self$options, name='dynamicNotice')
notice$setContent("This is a dynamic notice.")
self$results$insert(1, notice)