Move most of the R stuff into package