Fixing R script