Coerce to tbl_df (tibble)

Details

Our defined methods attempt to improve on the defaults in the tibble package to ensure that row names are not dropped by default, which is a poor default for bioinformatics. This is accomplished by setting rownames = "rowname" by default instead of rownames = NULL.

S3 as_tibble()

transformer extends as_tibble() method support for these S4 classes:

  • DataFrame.

  • GRanges.

S4 as()

Since tbl_df is a virtual class that extends tbl and data.frame, we need to define an S4 coercion method that allows us to use as() to coerce an object to a tibble.

See getClass("tbl_df") for details on how tibble is a virtual class.

See also

Examples

data(rse, package = "acidtest") stopifnot(is(rse, "RangedSummarizedExperiment")) df <- SummarizedExperiment::colData(rse) gr <- SummarizedExperiment::rowRanges(rse) ## DataFrame to tbl_df ==== x <- as(df, "tbl_df") x <- as_tibble(df) print(x)
#> # A tibble: 12 x 2 #> rowname condition #> <chr> <fct> #> 1 sample01 A #> 2 sample02 A #> 3 sample03 A #> 4 sample04 A #> 5 sample05 A #> 6 sample06 A #> 7 sample07 B #> 8 sample08 B #> 9 sample09 B #> 10 sample10 B #> 11 sample11 B #> 12 sample12 B
## GRanges to tbl_df ==== x <- as(gr, "tbl_df") x <- as_tibble(gr) print(x)
#> # A tibble: 500 x 11 #> rowname seqnames start end width strand geneID geneName geneBiotype #> <chr> <fct> <int> <int> <int> <fct> <chr> <fct> <fct> #> 1 gene001 X 1.01e8 1.01e8 12883 - ENSG0… TSPAN6 protein_co… #> 2 gene002 X 1.01e8 1.01e8 15084 + ENSG0… TNMD protein_co… #> 3 gene003 20 5.09e7 5.10e7 23689 - ENSG0… DPM1 protein_co… #> 4 gene004 1 1.70e8 1.70e8 44637 - ENSG0… SCYL3 protein_co… #> 5 gene005 1 1.70e8 1.70e8 192074 + ENSG0… C1orf112 protein_co… #> 6 gene006 1 2.76e7 2.76e7 23214 - ENSG0… FGR protein_co… #> 7 gene007 1 1.97e8 1.97e8 95627 + ENSG0… CFH protein_co… #> 8 gene008 6 1.43e8 1.44e8 16880 - ENSG0… FUCA2 protein_co… #> 9 gene009 6 5.35e7 5.36e7 119630 - ENSG0… GCLC protein_co… #> 10 gene010 6 4.11e7 4.11e7 27032 + ENSG0… NFYA protein_co… #> # … with 490 more rows, and 2 more variables: broadClass <fct>, #> # entrezID <I(list)>