fix wscript and update R code in /src/R