warn.and.subset: Extract subset and warn about omitted cases

Description Usage Arguments Value See Also Examples

Description

Extract row-subset of a data.frame according to a condition. If any cases (rows) are omitted, they are listed with a warning. Rows where the condition gives NA are omitted.

Usage

1
2
3
4
5
# This is the obligatory format, and is not very useful; look at EXAMPLES instead
warn.and.subset(x, cond,
    mess.head=deparse( substitute( x), width.cutoff=20, control=NULL, nlines=1),
    mess.cond=deparse( substitute( cond), width.cutoff=40, control=NULL, nlines=1),
    row.info=rownames( x), sub=TRUE)

Arguments

x

data.frame

cond

expression to evaluate in the context of data.frame. If sub=TRUE (the default), this will be substituted. If sub=FALSE, you can use a pre-assigned expression; in that case, you had better set mess.cond manually.

mess.head

description of data.frame (e.g. its name) for use in a warning.

mess.cond

description of the desired condition for use in a warning.

row.info

character vector that will describe rows; omitted elements appear in the warning

sub

should cond be treated as a literal expression to be evaluated, or as a pre-computed logical index?

# ...: just there to keep RCMD CHECK happy– for heaven's sake...

Value

The subsetted data.frame.

See Also

%where.warn% which is a less-flexible way of doing the same thing

Examples

1
2
3
4
df <- data.frame( a=1:3, b=letters[1:3])
df1 <- warn.and.subset( df, a %% 2 == 1, 'Boring example data.frame', 'even-valued "a"')
condo <- quote( a %% 2 == 1)
df2 <- warn.and.subset( df, condo, 'Same boring data.frame', deparse( condo), sub=FALSE)

mvbutils documentation built on May 2, 2019, 8:32 a.m.