Skip to content

Example 0

Jonathon Love edited this page Nov 17, 2016 · 6 revisions

This example is from the jmvexamples which implements an independent samples t-test. We recommend you download from its GitHub page here.

In the root of each jamovi R package is a jamovi/ folder, containing .a.yaml files describing each analysis. For this example, the relevant file is jmvexamples/jamovi/Example00.a.yaml which contains:

---
name:    Example00
title:   Example 0
version: "1.0.0"
jmc: "1.0.0"
description: >
  Example 0

options:
    - name: data
      type: Data

    - name: dependent
      title: Dependent variable
      type: Variable

    - name: group
      title: Grouping variable
      type: Variable

    - name: equVar
      title: Equal variances
      type: Bool
      default: true

The format of this file is YAML (more information about YAML can be found here, but it's pretty self explanatory).

The important parts here are the name, which will correspond to the name of the R function in the package, and the options form the arguments that the R function will receive. In this case, the first argument is called data, and it's type of Data means that it will expect an R data.frame. The second and third arguments are dependent and group and are of type Variable. These arguments will expect a character vector of length one, which will name a column in the data data.frame. The fourth argument equVar, is of type Bool and will accept the values TRUE or FALSE. Additionally, these options will correspond to UI elements in jamovi.

To build this example we will use the jamovi-compiler which you should already have installed.

From the terminal, navigate to the directory containing the Rjamovi-examples folder, and build it with the command:

jmc Rjamovi-examples

For each .a.yaml file, the corresponding files will be generated:

  • R/*.b.R
  • R/*.h.R
  • jamovi/ui/*.src.js

.b.R files are 'body' files, and are where the implementation of the analysis is placed. .h.R files are 'header' files, and should not be edited. .src.js files describe the user interface for the analysis. For now we will just look at the .b.R file, which is as follows:


# This file is a generated template, your changes will not be overwritten

Example00Class <- R6::R6Class(
    "Example00Class",
    inherit = Example00Base,
    private = list(
        .run = function() {

            # `self$data` contains the data
            # `self$options` contains the options
            # `self$results` contains the results object (to populate)

        })
)

In the next example, we will modify this function to implement the analysis.

In addition to generating these files, the compiler will build the package into jmvexamples.jmo, which is a jamovi module. From within jamovi, you can 'sideload' this module by choosing Modules ... -> Sideload ... -> select the .jmo file), and a new menu entry should appear listing each of the examples.

Select Example 00 from this list, and you will be greeted by a user interface that you can interact with. Interacting with the analysis options has no effect, because we have not provided the analysis implementation yet. This we will look at in the following example.

[Next >> Example 1](Example 1)

Tutorial

  • [Getting Started](Getting Started)
  • [Example 0](Example 0)
  • [Example 1](Example 1)
  • [Example 2](Example 2)
  • [Example 3](Example 3)
  • [Example 4](Example 4)
  • [Example 5](Example 5)

API

Clone this wiki locally