utils.check.datatype: Utility function to check the class of an object passed to a...

View source: R/utils.check.datatype.R

utils.check.datatypeR Documentation

Utility function to check the class of an object passed to a function

Description

WARNING: UTILITY SCRIPTS ARE FOR INTERNAL USE ONLY AND SHOULD NOT BE USED BY END USERS AS THEIR USE OUT OF CONTEXT COULD LEAD TO UNPREDICTABLE OUTCOMES.

Usage

utils.check.datatype(
  x,
  accept = c("genlight", "SNP", "SilicoDArT", "dartR"),
  verbose = NULL
)

Arguments

x

Name of the genlight object, dist matrix, data matrix, glPCA, or fixed difference list (fd) [required].

accept

Vector containing the classes of objects that are to be accepted. Matching is exact and case-sensitive. The entries 'genlight' and 'dartR' accept both genotype datatypes ('SNP' and 'SilicoDArT') [default c('genlight','SNP','SilicoDArT','dartR')].

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default NULL, unless specified using gl.set.verbosity].

Details

Most functions require access to a genlight object, dist matrix, data matrix or fixed difference list (fd), and this function checks that a genlight object or one of the above has been passed, whether the genlight object is a SNP dataset or a SilicoDArT object, and reports back if verbosity is >=2.

This function checks the class of passed object and sets the datatype to 'SNP', 'SilicoDArT', 'dist', 'matrix', 'glPca', 'fd', 'data.frame', 'list', or class(x)[1] as appropriate. A genlight object is classified from its ploidy slot alone (uniformly 1, 'SilicoDArT'; uniformly 2, 'SNP'; mixed or other ploidy is treated as 'SNP', with a warning) – genotype values, dartR flags and locus metrics are not consulted, with one exception: an object of uniform ploidy 2 whose non-missing genotypes are all 0 or 1, and which carries no SNP metadata (an empty loc.all slot and no SNP or SnpPosition locus metrics), is treated as SNP data with a warning (verbose >= 1) that it may be presence/absence (SilicoDArT) content mislabelled as SNP. Such an object is ambiguous: a small simulated sample or a hand-built object can lack the homozygous-alternate class. A clean SNP subset that merely lacks the homozygous-alternate class and keeps its loc.all slot raises no warning. Content-level validation beyond that check is the job of gl.compliance.check. Note also that this function checks to see if there are individuals or loci scored as all missing (NA) and if so, issues the user with a warning (verbose >= 2).

Value

datatype (returned invisibly): 'SNP' for SNP data, 'SilicoDArT' for P/A data, 'dist' for a distance matrix, 'matrix' for a data matrix, 'glPca' for an ordination file, 'fd' for a fixed difference object, 'data.frame' for a data frame, 'list' for any other list, or class(x)[1].

Author(s)

Author(s): Arthur Georges. Custodian: Arthur Georges – Post to https://groups.google.com/d/forum/dartr

See Also

Other utilities: gl.He(), gl.Ho(), gl.alf(), utils.allelic.richness(), utils.basic.stats(), utils.collapse.matrix(), utils.dart2genlight(), utils.dist.binary(), utils.fbm.amat(), utils.fbm.blocks(), utils.fbm.colblocks(), utils.fbm.colwise(), utils.fbm.copy(), utils.fbm.count.mean(), utils.fbm.decode(), utils.fbm.grm(), utils.fbm.has(), utils.fbm.new(), utils.fbm.pair.counts(), utils.fbm.reader(), utils.fbm.rowwise(), utils.fbm.tempfile(), utils.flag.start(), utils.het.pop(), utils.history.call(), utils.is.fixed(), utils.jackknife(), utils.n.var.invariant(), utils.plot.save(), utils.read.fasta(), utils.read.ped(), utils.recalc.avgpic(), utils.recalc.callrate(), utils.recalc.freqhets(), utils.recalc.freqhomref(), utils.recalc.freqhomsnp(), utils.recalc.maf(), utils.reset.flags(), utils.transpose(), utils.vcf.depth(), utils.vcfr2genlight.polyploid()

Examples

if (isTRUE(getOption("dartR_fbm"))) testset.gl <- gl.gen2fbm(testset.gl)
datatype <- utils.check.datatype(testset.gl)
datatype <- utils.check.datatype(as.matrix(testset.gl),accept='matrix')
fd <- gl.fixed.diff(testset.gl)
datatype <- utils.check.datatype(fd,accept='fd')
 

dartR.base documentation built on Nov. 18, 2026, 9:06 a.m.