RPGM 2.0 Docs

Simple tutorial

The aim of this tutorial is to easily show data and to provide results with a simple linear regression.
We will use the preloaded cars data.

Begin a new project with the File menu, then New and Project… and name our new project “LinearRegression”.

Your project appears with two files : LinearRegression.ppro, which contains the general properties of the program, and main.pseq which will contains our sequence of tasks (workflow).

Screenshot

The file main.pseq will contain the sequence of tasks as a chartflow and RPGM will execute each step by following the order of the chartflow. It has a Start step and we will connect our next steps to this one.

Screenshot

Push the F5 key to launch the program. It calls the main.pseq sequence which only has the Start step, it doesn’t do anything right now but we are going to add some steps.

Screenshot

Our first goal is to show the data of the cars variable which already exists in R. To do so, we must create a graphical interface and add it to the main.pseq file. Do a right click on the File explorer and choose Create GUI or use the menu File -> New -> GUI, and name the file ShowInputs.pgui. Before populating the interface, we must add it in our sequence. Go back on main.pseq and click on the GUI button to add a GUI to the sequence. On the right side of the chartflow, in the Properties settings, choose ShowInputs.pgui for the file. An easier way to add a step in the sequence is to drag and drop ShowInputs.pgui from the File explorer on the left into the sequence editor. You can move the boxes of the steps with the mouse. Now, add an arrow from the Start step to our new GUI step with the mouseby drag and dropping.

Screenshot

You can push F5 to see that we now enter in the GUI step, but it is empty for now. Go back in the ShowInputs.pgui file with a double click on its step in main.pseq or from the File explorer. In the GUI, choose the widget Label which is the default one and add the first element by clicking on _Add__.

  • Leave the ID field empty. The ID field is used for getting and manipulating the value of the widget in R. We will not use this for now.
  • In Value, write Linear Regression Cars, this is the text of the title.
  • In Font Size choose 32.

Screenshot

Use the viewer of the widget to see how each field works. The field Margin Top can be set to 0 in order to put an help text just below a previous widget.

By pressing F5, RPGM Client starts with the current state of the program:

Screenshot

It is not yet useful, but it gives an idea of how everything works. We will now add a Grid widget for displaying the data cars.

  • Add a new Grid widget by selecting Grid and clicking Add.
  • Set the ID field to ShowData, this will create a variable named ShowData if you want to access it in R after the user submit the form.
  • Set the Label field to Data:.
  • Set the Value field to cars. Make sure the R expr. checkbox is checked, as cars is an R expression which must be evaluated with R. Otherwise RPGM will try to set the value to “cars” as a string of 4 characters.
  • Set the Data type to Floats.
  • Check ShowHeaders for showing the headers of the data.

The ShowInputs.pgui file should look like this:

Screenshot

By pressing F5, the result is:

Screenshot

We will now write a R code for computing the linear regression. Use a right click on the File explorer and choose Create R script or use the menu File -> New -> R script, and name the new file Regression.R. Like for ShowInputs.pgui, we must add the script in the Sequencer. Go back on main.pseq and add a R Script step linked to the Regression.R file and connect it to ShowInputs.pgui so that the R file will be executed after our graphical interface.

Screenshot

We write the following code which computes the linear regression of dist against speed of the cars data. It also provides a graphic that we will display in another step.

png("regression.png")
    plot(cars, pch=16, col="darkblue", main="Linear regression")
    reg <- lm(dist ~ speed, data=cars)
    abline(reg$coefficients, col="red")
dev.off()

Screenshot

With F5, execute the program. The output folder can be open at the end where we have our graphic:

Screenshot

You get this graphic in the output folder. Now it’s time to show the graphic to the user, we will display it in a GUI directly in the Client. Create a new .pgui and call it Results, add it to main.pseq. The graphic will be display with an Image widget.

In Results.pgui, create a Label field with Results as value and 32 for the font size. Then add a second widget of type Image and set the value field to regression.png.

Screenshot

We get the following result when executing the program:

Screenshot

We finish by tweaking the project file:

  • Open LinearRegression.ppro ;
  • Fill the Program Name field with Linear Regression Cars ;
  • Download this image and place it the project folder ;
  • Drag and drop the image from the File Explorer to the Top logo field or manually select it ;
  • In the ChangeLog at the bottom, push the Add a new line button and fill the line.
    Your file should look like this:

Screenshot

Push F5 and watch how the top bar is updated.

Screenshot

This ends our first very simple program! You can download the program as a pgm file for the Client here and as a zip file containing all the project for the Editor here.