Skip to content

r scripting conventions

Sebastian Seitner edited this page Jan 4, 2018 · 16 revisions

Scripting Conventions

Working Directory

Each stack execution gets its own working directory set before execution.

The access is restricted to this directory and any descendents the scripts may create.

If any script tries to access other files or directories the script will be aborted with an exception.

Input

Each stack gets the name of the IAP report file as a global variable called 'data_file_name'

Passing values to next script

The result of the last command in a script will be passed to the next script in the stack.

This variable can be of any R datatype. e.g. this script will pass the vector created by c(1,2,3)

print("Pass the vector")
c(1,2,3)

The upcoming script can then access a global variable with the name 'phenopipe_input'. This variable is the exact same object returned by the previous script.

Status Updates

To send status updates 2 functions are injected to be used

  • setStatus(msg)
    • This function takes a character vector of length one to send.
  • setProgress(progress)
    • This function takes a numeric value to send. Usually from 0-100 to represent progress in %.

Example

The following will send a the message "My shiny new status message" and a progress value of 99 to the main server for the user to see in the web interface.

setStatus("My shiny new status message")
setProgress(99)

Variable and function names

Don't use names for your functions or your variables that start with 'phenopipe_' because these are reserved for internal use.

Plotting

As Renjin doesn't support the R graphics packages yet we had to implement a plotting interface to enable the plot generation in the R scripts. As soon as Renjin includes the graphics packages you will be able to use the usual R plotting functions and libraries.

Supported Chart types:

  • ScatterChart
  • BoxChart
  • BarChart
  • LineChart

How to plot

You just create an instance of the desired plot with appropriate parameters and call the function phenopipe_add_chart(your_chart_instance) to add and create the chart.

t = seq(0,10,0.1)
y = sin(t)
y1 = cos(t)
data <- cbind(t,y)
data <- rbind(data, cbind(t, y1))
groups <- c(rep("sin",length(t)),rep("cos",length(t)))
colors <- rainbow(2)

line <- LineChart$new(data = data,
    groups = factor(groups, levels = unique(groups)),
    colors = colors,
    legend = c("sine","cosine"),
    xLabel = "X",
    yLabel = "Y",
    title = "Test line plot"
)
phenopipe_add_chart(line)

For details about how to create the specific plot types please refer to the corresponding wiki pages

Bar Chart

Box Chart

Line Chart

Scatter Chart

Clone this wiki locally