added a scratch script for pure R implementation