32.2 The Scripts

32.2.1 Create your R Script with all Functions

The functions script contains all the routines and functions that are being applied in your plugin. Create an R Script file in the folder ”scripts” and start with the following section to install the insensa package and devtools package (but only if not installed already).

if(!requireNamespace(”insensa”)) { 
  if(!requireNamespace(”devtools”)) { 

We wont explain here how to program scripts R but we will give you an overview of the functions implemented in the Insensa package and how to use them.

Some general useful functions are:

  • insensa::iget: installes packages, only if not already available! So you can execute this function every time without unnecessary repeated installations. You should prefer this function over the install.packages.
  • AddVar: Save a variable to be used in Insensa-GIS and other plugins.
  • isActive: TRUE if script got executed from within Insensa-GIS. Really helpful to predefine variables for testing.

The following functions allow you to access values either set or calculated by Insensa GIS and use them in your R Script:

  • getVar: Returns a global variable or default value if the variable does not exist.
  • getCurrentFile: Relevant for ”Option” and ”InfoReader”. Returns the absolute file path of the file that holds the Option or InfoReader.
  • getSourceFiles: Relevant for ”Connections”. Returns the sources files from Insensa GIS.
  • OutputFile: Relevant for ”Connections” and ”Options”. Returnsabsolute file path of the new file that will be created.

Help and details how to use each function can be accessed, as usual, through R with using ?getVar or help(getVar).

32.2.2 Create your R Script for the UI

The settings script is optional and defines the settings dialog within the Insensa GIS user interface. The following functions allow you to create a standardized dialogue but with a relatively high flexibility:

  • UiAddBoolean: Create a boolean input field (Checkbox)
  • UiAddNumeric: Create a numeric input field
  • uiAddInputCharacter: Create a character input field
  • UiAddDirectory:Create a directory selection field
  • UiAddFile: Create a file selection field
  • UiAddSelectOne: Create a select ONE input field
  • UiAddSelectMultiple: Create a select MULTIPLE input field
  • UiAddInputPassword: Create a password input field
  • UIAddTable: Create an editable table view
  • UiAddEvent: Add events to create an interactive Ui.