added some support for SEXP type, making a vectorized function