parseRangeCode: Parse a numerical range expression

View source: R/parseRangeCode.R

parseRangeCodeR Documentation

Parse a numerical range expression

Description

parseRangeCode: Converts inequalities of up to two comparators stored in a vector of strings into an executable R expression. For instance, parseRangeCode(c("1 < Y < 20", "40 < Y")) will yield the expression (1<Y)&(Y<20)&(40<Y). parseRCode: simply parse an R string into an expression.

Usage

parseRangeCode(code)

Arguments

code

(Required) For parseRangeCode: A vector of strings that contain inequalities along with various seperators (see below). Each inequality should have either 1 or 2 comparators. For parseRCode: a code string. For parseRCode a character vector containing code.

Details

The parseRangeCode function converts various kinds of ranges/inequalities that are normally not handled by R into R-executable expressions. For instance it will convert inequalities of the form "A < B < C" into (A < B) & (B < C), where < may be replaced with any comparator. Moreover it allows inqualities to be concatenated by the symbols "&", ";" or "," which are all treated as equivalent to the logical "and" (i.e. "&"). Thus "A < B <C & D > E, F <= G" will be converted into (A < B)&(B < C)&(D > E)&(F <= G). In addition if code is a vector with more than one element, each element will be parsed and then concatenated into a single expression with "&". Hence c("1 < Y", "2 < Z <= 5") would become (1 < Y)&(2 < Z)&(Z <= 5).

Value

An expression constructed as detailed above.

Warning

The character "|" is not allowed in any of the expressions contained in "code" for the parseRangeCode function.

Author(s)

Romain Francois

See Also

subset, parse

Examples


# Examples of using subsets
 ## Not run: 
exData <- data.frame( Y = rnorm(200), B = rnorm( 200 ) )
subs1 <- parseRangeCode("1 < Y < 10 & 1 > B > -2")
exData[ eval(subs1, exData), ]

subs2 <- parseRangeCode(c("1 < Y < 10", "1 > B > -2"))
exData[ eval(subs1, exData), ]

expr <- parseRCode("rnorm(30)")
eval( expr ) 
## End(Not run)

MikeKSmith/MSToolkit documentation built on Feb. 15, 2024, 5:32 p.m.