Install Rcpp library.Add the following lines in code.
#include <Rcpp.h>
using namespace Rcpp;
//[[Rcpp::export]]
......
Save file as *.cpp and run inside R