RPGM 2.0 Docs

Script R functions

This set of functions are available while a R Script is executing in a Script step in RPGM.

script.setProgress(show, progress, message)

Show or hide a progress bar in the script step:

script.setProgress

  • show must be set to TRUE for showing the bar and to FALSE for hiding it
  • progress is a number between 0 and 100 representing the progression
  • message is a custom message to show below the progress bar

The code used to display the progress bar above was: script.setProgress(TRUE, 60, "Exporting to csv format...");
Here is a complete example simulating a 10 seconds length script which updates the progress bar each two seconds:

getCoolText <- function(i)
{
    if(i == "0") return("Calculating ISS position...");
    if(i == "1") return("Generating graphics...");
    if(i == "2") return("Fetching infos from file...");
    if(i == "3") return("Exporting to csv format...");
    return("Success!");
}

starttime <- proc.time()[3][1];
lastout <- starttime;
i <- 0;
script.setProgress(TRUE, i*20, getCoolText(i));
continue <- TRUE;
while(continue)
{
    newtime <- proc.time()[3][1];
    if(newtime - starttime > 10)
    {
        continue = FALSE;
    }
    if(newtime - lastout > 2)
    {
        i <- i + 1;
        script.setProgress(TRUE, i*20, getCoolText(i));
        lastout <- newtime;
    }
}