added function for r package