Function amended by adding base:: to call R base functions