Replaced C++ line with an R version