Update R code

Add code for State flag.