R connection speedup and error checking