Both single element subsetting via [[ and $, as well as multi-element subsetting via [ are available for prt objects. Subsetting semantics are modeled after those of the tibble class with the main difference being that there tibble returns tibble objects, prt returns data.tables. Differences to base R include that partial column name matching for $ is not allowed and coercion to lower dimensions for [ is always disabled by default. As prt objects are immutable, all subset-replace functions ([[<-, $<- and [<-) yield an error when passed a prt object.

# S3 method for prt
[[(x, i, j, ..., exact = TRUE)

# S3 method for prt
$(x, name)

# S3 method for prt
[(x, i, j, drop = FALSE)

Arguments

x

A prt object.

i, j

Row/column indexes. If j is omitted, i is used as column index.

...

Generic compatibility: any further arguments are ignored.

exact

Generic compatibility: only the default value of TRUE is supported.

name

A literal character string or a name (possibly backtick quoted).

drop

Coerce to a vector if fetching one column via tbl[, j]. Default FALSE, ignored when accessing a column via tbl[j].

Examples

dat <- as_prt(mtcars)

identical(dat$mpg, dat[["mpg"]])
#> [1] TRUE

dat$mp
#> Warning: Unknown or uninitialised column: `mp`.
#> NULL
mtcars$mp
#>  [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
#> [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
#> [31] 15.0 21.4

identical(dim(dat["mpg"]), dim(mtcars["mpg"]))
#> [1] TRUE
identical(dim(dat[, "mpg"]), dim(mtcars[, "mpg"]))
#> [1] FALSE
identical(dim(dat[1L, ]), dim(mtcars[1L, ]))
#> [1] TRUE