check4tyle: checks the type, the length and the content of some standard...

Description Usage Arguments Details Value Examples

View source: R/f0.rbsb1.code.r

Description

checks the type, the length and the content of some standard object. If not correct, a message and a fatal error are issued. NA are detected and considered as wrong.

Usage

1
2
check4tyle(x, typ, len=-1, con=rbsb.num0, message=NULL, fatal=TRUE,
	  na.rm=FALSE)

Arguments

x

object to be checked.

typ

The list of correct types, among 'null', 'integer', 'numeric', 'character', 'logical', 'list', 'any', 'function', 'data.frame', 'matrix'. Also are 'nlogical', 'ninteger', 'nnumeric' and 'ncharacter' for named structures. As understood, 'any' implies that no check of the type is performed.

len

If length(len)==1, the exact length to be checked, if not must be of length two for the possible range of length(x). When -1, no check on the length is performed.
For data.frame, it is the number of columns. When na.rm the check is made after removing the NA values.

con

If length(con)>0, some check about the content of x is done for some of the types. More precisely for (integer, numeric): all values must belong to the interval [con[1],con[2]] and for (character), the set of possible character(1) is described by con.

message

Some additional message to be issued before stopping in case of error.

fatal

what to do when discovering an inconsistency ? TRUE: this function prints the message and stops; FALSE: this function returns the message as a character.

na.rm

Must the NA values be removed before checking? This is implemented only for the types integer, numeric, character and logical.

Details

'integer' has not got the meaning in is.integer R standard function. 'null' must be understood as resulting TRUE with function isempty.
'Named character' is different from 'character': rbsb.chara can be used for this purpose.

Value

a character with the message(s), when everything is OK returns a character(0). But when fatal if not OK prints the message and stops.

Examples

1
2
3
4
5
 rbsb3k("RESET"); # for R checking compliance (useless)
 check4tyle(letters, c("numeric", "character"), c(20, 30), message="!OK");
 check4tyle(structure("A", .Names="a"), "ncharacter", -1, LETTERS);
 check4tyle("A", "ncharacter", -1, message="BAD", fatal=FALSE);
 check4tyle(structure("A", .Names="a"), "character", -1, letters, "bad", fatal=FALSE);

rbsb documentation built on May 31, 2017, 1:45 a.m.