fix stdin problem and find R from $PATH