require(inline) require(Rcpp) generateIndex14 <- local( { fun <- cxxfunction( signature( n_ = "integer", width_ = "integer", format_ = "character" ), ' int n = as<int>(n_) ; int width = as<int>( width_ ) ; const char* format = as<const char*>( format_ ) ; std::string buffer( width, \'0\' ) ; std::vector< std::string > elements( n ) ; for( int i=0; i<n; i++){ sprintf( const_cast<char*>(buffer.data() ), format, i+1 ) ; elements[i] = buffer.c_str() ; } std::stringstream ss ; CharacterVector res( n*(n-1)/2) ; for( int i=0, k=0; i<n-1; i++){ for(int j=i+1; j<n; j++, k++){ ss << "i" << elements[i] << "." << elements[j]; res[k] = ss.str(); ss.str( "" ) ; } } return res ; ', plugin = "Rcpp" ) function( n ){ width <- ceiling( log10(n+1) ) fun( n, width, sprintf("%%0%dd", width) ) } } ) generateIndex14( 10 )