Skip to content

Commit 9b736e6

Browse files
committed
Added checks for unused arguments in functions with ...
1 parent f6f2b57 commit 9b736e6

File tree

8 files changed

+42
-6
lines changed

8 files changed

+42
-6
lines changed

R/fstats.R

+5
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ fix_ploidy = function(xmat) {
446446
get_f2 = function(f2_data, pops = NULL, pops2 = NULL, afprod = FALSE, verbose = TRUE, ...) {
447447

448448
stopifnot(!is.character(f2_data) || dir.exists(f2_data) || is_geno_prefix(f2_data))
449+
argnam = c(names(formals(f2_from_geno)), names(formals(f2_from_precomp)), names(formals(qpfstats)))
450+
if(!all(...names() %in% argnam)) {
451+
notused = setdiff(...names(), argnam)
452+
stop(paste0("The following arguments are not recognized: '", paste0(notused, collapse = "', '"), "'"))
453+
}
449454
if(!is.null(pops) && is.null(pops2)) pops2 = pops
450455
if(!is.character(f2_data)) {
451456
f2_blocks = f2_data

R/io.R

+9-2
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,10 @@ extract_f2 = function(pref, outdir, inds = NULL, pops = NULL, blgsize = 0.05, ma
10631063
adjust_pseudohaploid = TRUE, cols_per_chunk = NULL, fst = TRUE, afprod = TRUE,
10641064
poly_only = c('f2'), apply_corr = TRUE, qpfstats = FALSE, n_cores = 1, verbose = TRUE, ...) {
10651065

1066+
if(!all(...names() %in% names(formals(admixtools::qpfstats)))) {
1067+
notused = setdiff(...names(), names(formals(admixtools::qpfstats)))
1068+
stop(paste0("The following arguments are not recognized: '", paste0(notused, collapse = "', '"), "'"))
1069+
}
10661070
if(!is.null(cols_per_chunk)) {
10671071
stopifnot(is.null(pops2))
10681072
snpfile = extract_f2_large(pref, outdir, inds = inds, pops = pops, blgsize = blgsize,
@@ -2182,12 +2186,15 @@ extract_samples = function(inpref, outpref, inds = NULL, pops = NULL, overwrite
21822186
#' @param block_lengths An optional vector with block lengths. If `NULL`, block lengths will be computed.
21832187
#' @param f4mode If `TRUE`: f4 is computed from allele frequencies `a`, `b`, `c`, and `d` as `(a-b)*(c-d)`. if `FALSE`, D-statistics are computed instead, defined as `(a-b)*(c-d) / ((a + b - 2*a*b) * (c + d - 2*c*d))`, which is the same as `(P(ABBA) - P(BABA)) / (P(ABBA) + P(BABA))`.
21842188
#' @param allsnps Use all SNPs with allele frequency estimates in every population of any given population quadruple. If `FALSE` (the default) only SNPs which are present in all populations in `popcombs` (or any given model in it) will be used. Setting `allsnps = TRUE` in the presence of large amounts of missing data might lead to false positive results.
2189+
#' @param poly_only Only keep SNPs with mean allele frequency not equal to 0 or 1.
2190+
#' @param snpwt A vector of SNP weights
2191+
#' @param keepsnps A vector of SNP IDs to keep
21852192
#' @param verbose Print progress updates
21862193
#' @return A data frame with per-block f4-statistics for each population quadruple.
21872194
f4blockdat_from_geno = function(pref, popcombs = NULL, left = NULL, right = NULL, auto_only = TRUE,
21882195
blgsize = 0.05,
21892196
block_lengths = NULL, f4mode = TRUE, allsnps = FALSE,
2190-
poly_only = FALSE, verbose = TRUE, snpwt = NULL, ...) {
2197+
poly_only = FALSE, snpwt = NULL, keepsnps = NULL, verbose = TRUE) {
21912198

21922199
stopifnot(!is.null(popcombs) || (!is.null(left) && !is.null(right)))
21932200
stopifnot(is.null(popcombs) || is.null(left) && is.null(right))
@@ -2233,7 +2240,7 @@ f4blockdat_from_geno = function(pref, popcombs = NULL, left = NULL, right = NULL
22332240

22342241
snpfile$keep = TRUE
22352242
if(auto_only) snpfile %<>% mutate(keep = as.numeric(gsub('[a-zA-Z]+', '', CHR)) <= 22)
2236-
if('keepsnps' %in% names(list(...))) snpfile %<>% mutate(keep = keep & SNP %in% list(...)$keepsnps)
2243+
if(!is.null(keepsnps)) snpfile %<>% mutate(keep = keep & SNP %in% keepsnps)
22372244
nsnpaut = sum(snpfile$keep)
22382245
pops = unique(c(popcombs$pop1, popcombs$pop2, popcombs$pop3, popcombs$pop4))
22392246

R/qpadm.R

+7-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ qpadm = function(data, left, right, target, f4blocks = NULL,
163163
#----------------- prepare f4 stats -----------------
164164
f2_blocks = NULL
165165
args = list(...)
166+
if(length(args) > 0 && (!is.null(f4blocks) || !is_geno_prefix(data))) {
167+
stop(paste0("The following arguments are not used: '", paste0(names(args), collapse = "', '"), "'"))
168+
}
169+
if(!all(names(args) %in% names(formals(f4blockdat_from_geno)))) {
170+
notused = setdiff(names(args), names(formals(f4blockdat_from_geno)))
171+
stop(paste0("The following arguments are not recognized: '", paste0(notused, collapse = "', '"), "'"))
172+
}
166173
if(is.null(f4blocks)) {
167174
if(all(file.exists(left, right))) {
168175
left %<>% readLines
@@ -919,7 +926,6 @@ qpadmmodels_to_popcombs = function(models) {
919926
#' @return A list where each element is the output of one qpadm model.
920927
#' @examples
921928
#' \dontrun{
922-
#' pops = paste0('pop', 1:10)
923929
#' # the following specifies two models: one with 2/3/1 and one with 1/2/1 left/right/target populations
924930
#' models = tibble(
925931
#' left = list(c('pop1', 'pop2'), c('pop3')),

R/qpdstat.R

+4
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ qpdstat_geno = function(pref, popcombs, blgsize = 0.05, block_lengths = NULL,
428428
qp3pop_geno = function(pref, popcombs, blgsize = 0.05, block_lengths = NULL,
429429
boot = FALSE, allsnps = TRUE, poly_only = FALSE, verbose = TRUE, ...) {
430430

431+
if(!all(...names() %in% names(formals(f3blockdat_from_geno)))) {
432+
notused = setdiff(...names(), names(formals(f3blockdat_from_geno)))
433+
stop(paste0("The following arguments are not recognized: '", paste0(notused, collapse = "', '"), "'"))
434+
}
431435
pref = normalizePath(pref, mustWork = FALSE)
432436
f3blockdat = f3blockdat_from_geno(pref, popcombs, blgsize = blgsize, block_lengths = block_lengths,
433437
allsnps = allsnps, poly_only = poly_only, verbose = verbose, ...)

R/qpgraph.R

+5
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,11 @@ qpgraph_resample_snps2 = function(f2_blocks, graph, f2_blocks_test, verbose = TR
765765
#' @seealso \code{\link{compare_fits}}
766766
qpgraph_resample_multi = function(f2_blocks, graphlist, nboot, verbose = TRUE, ...) {
767767

768+
argnam = names(formals(qpgraph))
769+
if(!all(...names() %in% argnam)) {
770+
notused = setdiff(...names(), argnam)
771+
stop(paste0("The following arguments are not recognized: '", paste0(notused, collapse = "', '"), "'"))
772+
}
768773
boo = boo_list(f2_blocks, nboot = nboot)
769774
#f3pre = map(graphlist, ~qpgraph_precompute_f3(f2_blocks, get_leafnames(.))$ppinv)
770775
#map2(graphlist, f3pre, function(.x, .y, ...) qpgraph_resample_snps2(

R/toposearch.R

+4
Original file line numberDiff line numberDiff line change
@@ -2629,6 +2629,10 @@ find_graphs = function(data, numadmix = 0, outpop = NULL, stop_gen = 100, stop_g
26292629
numadmix = numadmix(graph)
26302630
}
26312631
ell = list(...)
2632+
if(!all(names(ell) %in% names(formals(qpgraph)))) {
2633+
notused = setdiff(names(ell), names(formals(qpgraph)))
2634+
stop(paste0("The following arguments are not recognized: '", paste0(notused, collapse = "', '"), "'"))
2635+
}
26322636
if('f3basepop' %in% names(ell)) {
26332637
f3basepop = ell$f3basepop
26342638
} else {

man/f4blockdat_from_geno.Rd

+8-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/qpadm_multi.Rd

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)