fixed up some problems with R file, added a check to bash file