start of R wrapper