TestArg: Test if the argument of a function is of a given class or...

Description Usage Arguments Value Examples

View source: R/TestArg.R

Description

If the avar object is of the class expectedClass, then the function returns the avar object as is If avar is NULL, then the function returns NULL If avar is a character string corresponding to an existing file, then the file is imported using importFUN Else, the function stops and returns an error

Usage

1
TestArg(avar, importFUN, expectedClass, ...)

Arguments

avar

Either an object or a path to a file to import with importFUN

importFUN

Function to import avar if it is a path. The function must return an object of class expectedClass

expectedClass

Character vector. expected class of the object avar

...

further arguments passed to importFUN

Value

either NULL if avar is NULL or an object of class expectedClass

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
# With an object in R
TestArg(1:10, expectedClass = "integer") #returns 1:10
TestArg(1:10, expectedClass = "character") #returns an error

#With a path to a file
Path2Blast <- system.file("extdata", "BAC02_Blast18S.res", package = "NanoBAC")
TestArg(Path2Blast, readBlast, "tbl_df") #returns the imported file
TestArg(Path2Blast, readBlast, "integer") #returns an error

## End(Not run)

pgpmartin/NanoBAC documentation built on Dec. 11, 2020, 9:51 a.m.