• tibble 只是多了点属性,是S3 函数让其强大
l <- list(x = rnorm(2), y = 1:2);

paristools:::as_tibble(l)
#> # A tibble: 2 × 2
#>        x     y
#>    <dbl> <int>
#> 1 0.0803     1
#> 2 0.0119     2

tibble::as_tibble(l)
#> # A tibble: 2 × 2
#>        x     y
#>    <dbl> <int>
#> 1 0.0803     1
#> 2 0.0119     2

paristools:::as_tibble(l)
#> # A tibble: 2 × 2
#>        x     y
#>    <dbl> <int>
#> 1 0.0803     1
#> 2 0.0119     2
  • 不忍心删,顺便演示 vignette 中使用 Rcpp 代码

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

# include <Rcpp.h>
// [[Rcpp::depends(paristools)]]
# include <paristools.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 paristools::as_tibble(l);
}
demo_as_tibble()
#> # A tibble: 3 × 2
#>       a b    
#>   <int> <chr>
#> 1     1 a    
#> 2     2 b    
#> 3     3 c