subsetting: Subsetting operations

Description Usage Arguments Examples

Description

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.

Usage

1
2
3
4
5
6
7
8
## S3 method for class 'prt'
x[[i, j, ..., exact = TRUE]]

## S3 method for class 'prt'
x$name

## S3 method for class '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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
dat <- as_prt(mtcars)

identical(dat$mpg, dat[["mpg"]])

dat$mp
mtcars$mp

identical(dim(dat["mpg"]), dim(mtcars["mpg"]))
identical(dim(dat[, "mpg"]), dim(mtcars[, "mpg"]))
identical(dim(dat[1L, ]), dim(mtcars[1L, ]))

prt documentation built on May 16, 2021, 9:07 a.m.