convert list to tibble

as_tibble() converts a non-empty List of equal-length elements into a tibble.

# include <Rcpp.h>
// [[Rcpp::depends(Rcppzhuoer)]]
# include <Rcppzhuoer.h>
using namespace Rcpp;

//[[Rcpp::export]]
List demo_as_tibble() {
    // construct a list
    IntegerVector a = IntegerVector::create(1, 2, 3);
    CharacterVector b = CharacterVector::create("a", "b", "c");
    List l = List::create(Named("a") = a, Named("b") = b);
    
    return Rcppzhuoer::as_tibble(l);
}
demo_as_tibble()
#>   a b
#> 1 1 a
#> 2 2 b
#> 3 3 c

paste arguments into a std::string

paste() can recieve arbitrary number and types of arguments.

It converts them into strings via << operator, then concatenate into a single std::string.

Besides, We enable std::boolalpha.

# include <Rcpp.h>
// [[Rcpp::depends(Rcppzhuoer)]]
# include <Rcppzhuoer.h>
using namespace Rcpp;

//[[Rcpp::export]]
void demo_paste() {
    std::string str = Rcppzhuoer::paste("hello ", 'h', "adle", 'y', " * ", 3.5);
    Rcout << str << std::endl; 
    
    Rcout << Rcppzhuoer::paste("a true: ", 1, ' ', true);
}
demo_paste()
#> hello hadley * 3.5
#> a true: 1 true