implement a function to write R script for poison