coerce-data.table: Coerce to data table

Description Usage Arguments Details Value S3 as.data.table() S4 as() Note See Also Examples

Description

Coerce to data.table.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
as.data.table(x, keep.rownames = FALSE, ...)

## S3 method for class 'DataFrame'
as.data.table(x, keep.rownames = TRUE, ...)

## S3 method for class 'IPosRanges'
as.data.table(x, keep.rownames = TRUE, ...)

## S3 method for class 'GenomicRanges'
as.data.table(x, keep.rownames = TRUE, ...)

Arguments

x

An R object.

keep.rownames

Default is FALSE. If TRUE, adds the input object's names as a separate column named "rn". keep.rownames = "id" names the column "id" instead.

...

Additional arguments to be passed to or from other methods.

Details

Our defined methods attempt to improve on the defaults in the data.table package to ensure that row names are not dropped by default, which is a poor default for bioinformatics. This is accomplished by setting keep.rownames = "rowname" by default instead of keep.rownames = NULL. Note that we're manually defining the "rowname" column instead of using TRUE, to match the conventions used in our as_tibble() methods.

Value

data.table.

S3 as.data.table()

transformer extends as.data.table() method support for these S4 classes:

S4 as()

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

See getClass("data.table") for details.

Note

Updated 2020-01-08.

See Also

data.table::as.data.table().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
data(DataFrame, GRanges, IRanges, package = "acidtest")

## DataFrame to data.table ====
x <- as(DataFrame, "data.table")
x <- as.data.table(DataFrame)
print(x)

## GenomicRanges to data.table ====
x <- as(GRanges, "data.table")
x <- as.data.table(GRanges)
print(x)

## IRanges to data.table ====
x <- as(IRanges, "data.table")
x <- as.data.table(IRanges)
print(x)

acidgenomics/transformer documentation built on Jan. 9, 2020, 11:34 a.m.