R Script Functions
These functions are available while an R script is executing in a Script step in RPGM.
Functions
script.setProgress(show, progress, message)
Shows or hides a progress bar in the current script step.
show
must be set toTRUE
for showing the bar and toFALSE
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.
Here is an example code:
Here is a complete example simulating a 10 seconds length script which updates the progress bar every 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;
}
}