Add try-catch in R