copy from R-forge