Coerce to tbl_df.

# S3 method for DataFrame
as_tibble(
  x,
  ...,
  rownames = pkgconfig::get_config("tibble::rownames", "rowname")
)

# S3 method for IPosRanges
as_tibble(
  x,
  ...,
  rownames = pkgconfig::get_config("tibble::rownames", "rowname")
)

# S3 method for GenomicRanges
as_tibble(
  x,
  ...,
  rownames = pkgconfig::get_config("tibble::rownames", "rowname")
)

Arguments

x

A data frame, list, matrix, or other object that could reasonably be coerced to a tibble.

...

Other arguments passed on to individual methods.

rownames

How to treat existing row names of a data frame or matrix:

  • NULL: remove row names. This is the default.

  • NA: keep row names.

  • A string: the name of a new column. Existing rownames are transferred into this column and the row.names attribute is deleted. Read more in rownames.

Value

tbl_df.

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(DataFrame, GRanges, IRanges, package = "acidtest") ## DataFrame to tbl_df ==== x <- as(DataFrame, "tbl_df") x <- as_tibble(DataFrame) print(x)
#> # A tibble: 4 x 5 #> rowname sample01 sample02 sample03 sample04 #> <chr> <int> <int> <int> <int> #> 1 gene01 1 2 3 4 #> 2 gene02 5 6 7 8 #> 3 gene03 9 10 11 12 #> 4 gene04 13 14 15 16
## GenomicRanges to tbl_df ==== x <- as(GRanges, "tbl_df") x <- as_tibble(GRanges) 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(IRanges, "tbl_df") x <- as_tibble(IRanges) print(x)
#> # A tibble: 3 x 5 #> rowname start end width score #> <chr> <int> <int> <int> <int> #> 1 a 1 5 5 1 #> 2 b 10 14 5 2 #> 3 c 20 24 5 3