-
Notifications
You must be signed in to change notification settings - Fork 4
r scripting conventions
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.
Each stack gets some metadata passed by the server. It is stored in the gloabl variable 'phenopipe_metadata' and is a named list. It contains the following entries:
Key | Description |
---|---|
data_file_name | Indicates the name of the file of the filtered IAP report. It is located at the root of the working directory |
control_treatment_name | The name of the treatment which represents the control group. Matches an entry in the column 'treatment' of the IAP report |
The IAP report file is filtered and copied to the working directory of the stack before executing the R code. The filtering is based on the current state of excluded snapshots on the main Phenopipe server.
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.
To send status updates 2 functions are injected to be used
- phenopipe_set_status(msg)
- This function takes a character vector of length one to send.
- phenopipe_set_progress(progress)
- This function takes a numeric value to send. Usually from 0-100 to represent progress in %.
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)
Do not use names for your functions or your variables that start with the prefix 'phenopipe_' because these are reserved for internal use, but you are free to access them. Doing so may lead to unexpected behaviour.
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.
- ScatterChart
- BoxChart
- BarChart
- LineChart
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