R Code for Demos