Skip to content

Instantly share code, notes, and snippets.

How to Write R Analyses for JASP

R code for JASP should follow JASP's R style guide.

This document will guide you through writing an R analysis for JASP. Two things should be noted before we get started. First, this guide assumes that you have knowledge about basic R concepts such as functions. Second, writing an R analysis is necessary but not sufficient to create a new module for JASP. For this goal, other files (such as the UI, json etc.) need to be created. The creation of these other files is not discussed here.

Every JASP R analysis will consist of several types of functions:

  1. a single main analysis function that organizes the analysis and its output,
  2. one or multiple results functions that compute the results that will be displayed,
  3. one or multiple create functions that create output elements (tables, plots, containers), and

JASP - Design for new R Analysis

The main goal of this design is to make as easy as possible for R programmers to write their own analyses and produce the output of the results in an intuitive way.

1. Current state of art

Programming an analysis in R for JASP is currently quite difficult and error-prone. A lot of lines of code is necessary to read the data, handle the state and options, and also to describe the results with complicated meta information. This code is not intuitive for R programmers.

First work was done by Tim de Jong to simplify the task of the R programmer. This work tried as much as possible to remove all meta data from the R analysis itself. This is done by making JASP clever enough to induce from the types (data.frame, plot or list) of the objects returned by the analysis, which output should be displayed. Also, a JSON file is used to specify all extra information needed for the output.