to write csv file including errors for runing on R