bug fix in R script