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(df, gr, ir, package = "acidtest") ## DataFrame to tbl_df ==== x <- as(df, "tbl_df") x <- as_tibble(df) print(x)
#> # A tibble: 4 x 5 #> rowname sample1 sample2 sample3 sample4 #> <chr> <int> <int> <int> <int> #> 1 ENSG00000000001 1 5 9 13 #> 2 ENSG00000000002 2 6 10 14 #> 3 ENSG00000000003 3 7 11 15 #> 4 ENSG00000000004 4 8 12 16
## GRanges to tbl_df ==== x <- as(gr, "tbl_df") x <- as_tibble(gr) print(x)
#> # A tibble: 5 x 8 #> rowname seqnames start end width strand geneID geneName #> <chr> <fct> <int> <int> <int> <fct> <chr> <chr> #> 1 ENSG000000000… X 1.01e8 1.01e8 12883 - ENSG00000000… TSPAN6 #> 2 ENSG000000000… X 1.01e8 1.01e8 15084 + ENSG00000000… TNMD #> 3 ENSG000000004… 20 5.09e7 5.10e7 23689 - ENSG00000000… DPM1 #> 4 ENSG000000004… 1 1.70e8 1.70e8 44637 - ENSG00000000… SCYL3 #> 5 ENSG000000004… 1 1.70e8 1.70e8 192074 + ENSG00000000… C1orf112
## IRanges to tbl_df ==== x <- as(ir, "tbl_df")
#> Error in as(ir, "tbl_df"): no method or default for coercing “IRanges” to “tbl_df”
x <- as_tibble(ir) print(x)
#> # A tibble: 3 x 4 #> start end width names #> <int> <int> <int> <chr> #> 1 1 5 5 a #> 2 10 14 5 b #> 3 20 24 5 c