Skip to content

Commit

Permalink
Resolve flags from R CMD CHECK
Browse files Browse the repository at this point in the history
Added tibble and rlang to Imports. Both needed for dplyr, therefore the PoolTestR dependency footprint is unchanged.

Added tibble:: and stats:: calls for functions in those packages.

Imported .data from rlang in package.R file.

Update dplyr function calls - data masking and tidy selection (refer to this vignette: https://dplyr.tidyverse.org/articles/in-packages.html)

In R files, updated T and F to TRUE and FALSE as recommended in R Packages 2nd ed.

Ran devtools document and check functions, then tested all 6 modes of PoolPrev and HierPoolPrev. Also tested print method on all 6 modes. Ran successfully.

Tidied description with usethis::use_tidy_description()
  • Loading branch information
caitlinch committed Oct 29, 2024
1 parent 7a21016 commit 63a2222
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 60 deletions.
60 changes: 32 additions & 28 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@ Package: PoolTestR
Title: Prevalence and Regression for Pool-Tested (Group-Tested) Data
Version: 0.2.0
Authors@R: c(
person(given = "Angus", family = "McLure", role = c("aut", "cre"),
email = "[email protected]",comment = c(ORCID = "0000-0003-2551-3059") ),
person(given = "Caitlin", family = "Cherryh", role = c("ctb"),
comment = c(ORCID = "0000-0001-6146-4376") )
)
person("Angus", "McLure", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2551-3059")),
person("Caitlin", "Cherryh", role = "ctb",
comment = c(ORCID = "0000-0001-6146-4376"))
)
Description: An easy-to-use tool for working with presence/absence tests
on 'pooled' or 'grouped' samples. The primary application is for
estimating prevalence of a marker in a population based on the results
of tests on pooled specimens. This sampling method is often employed
in surveillance of rare conditions in humans or animals (e.g.
molecular xenomonitoring). The package was initially conceived as an
R-based alternative to the molecular xenomonitoring software,
'PoolScreen' <https://sites.uab.edu/statgenetics/software/>. However,
it goes further, allowing for estimates of prevalence to be adjusted
for hierarchical sampling frames, and perform flexible mixed-effect
regression analyses (McLure et al. Environmental Modelling and
Software. <DOI:10.1016/j.envsoft.2021.105158>). The package is
currently in early stages, however more features are planned or in the
works: e.g. adjustments for imperfect test specificity/sensitivity,
functions for helping with optimal experimental design, and functions
for spatial modelling.
License: GPL (>= 3)
URL: https://github.com/AngusMcLure/PoolTestR
BugReports: https://github.com/AngusMcLure/PoolTestR
Description: An easy-to-use tool for working with presence/absence tests on 'pooled'
or 'grouped' samples. The primary application is for estimating prevalence of
a marker in a population based on the results of tests on pooled specimens.
This sampling method is often employed in surveillance of rare conditions in
humans or animals (e.g. molecular xenomonitoring). The package was initially
conceived as an R-based alternative to the molecular xenomonitoring software,
'PoolScreen' <https://sites.uab.edu/statgenetics/software/>. However, it goes
further, allowing for estimates of prevalence to be adjusted for hierarchical
sampling frames, and perform flexible mixed-effect regression analyses
(McLure et al. Environmental Modelling and Software.
<DOI:10.1016/j.envsoft.2021.105158>). The package is currently in early stages,
however more features are planned or in the works: e.g. adjustments for
imperfect test specificity/sensitivity, functions for helping with optimal
experimental design, and functions for spatial modelling.
License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
Biarch: true
Depends:
R (>= 3.4.0)
Imports:
Expand All @@ -37,19 +36,24 @@ Imports:
progress,
Rcpp (>= 0.12.0),
RcppParallel (>= 5.0.1),
rlang,
rstan (>= 2.26.0),
rstantools (>= 2.3.1.1),
stats,
stringr
stringr,
tibble
Suggests:
covr
LinkingTo:
BH (>= 1.66.0),
Rcpp (>= 0.12.0),
RcppEigen (>= 0.3.3.3.0),
RcppParallel (>= 5.0.1),
rstan (>= 2.26.0),
StanHeaders (>= 2.26.0)
SystemRequirements: GNU make
RoxygenNote: 7.3.2
Biarch: true
Encoding: UTF-8
Language: en-AU
Suggests:
covr
LazyData: true
RoxygenNote: 7.3.2
SystemRequirements: GNU make
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ import(Rcpp)
import(dplyr)
import(methods)
import(rstan)
importFrom(rlang,.data)
useDynLib(PoolTestR, .registration = TRUE)
18 changes: 9 additions & 9 deletions R/HierPoolPrev.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ HierPoolPrev <- function(data,result,poolSize,hierarchy,...,
cores = cores,
control = control)
#return(sfit)
sfit <- extract(sfit) %>% dplyr::as_tibble() %>% rowwise()
sfit <- extract(sfit) %>% tibble::as_tibble() %>% rowwise()

prevICC <- sfit %>%
transmute(prev = meanlinknormal(Intercept,
total_group_sd,
transmute(prev = meanlinknormal(.data$Intercept,
.data$total_group_sd,
stats::plogis),
ICC = t(ICC(Intercept[1],
group_sd,
ICC = t(ICC(.data$Intercept[1],
.data$group_sd,
.mean = prev,
link = 'logit',
method = 'approx')))
Expand All @@ -207,7 +207,7 @@ HierPoolPrev <- function(data,result,poolSize,hierarchy,...,
estimate.type = 'consistent'
}

out <- dplyr::tibble(PrevBayes =
out <- tibble::tibble(PrevBayes =
switch(estimate.type,
consistent = mean(prev),
zero = 0)
Expand Down Expand Up @@ -283,11 +283,11 @@ print.HierPoolPrevOutput <- function(x, ...) {
icc_names <- attr(x$ICC, "dimnames")[[2]]
trimmed_object <- x %>%
mutate(PrevBayes = paste0(" ",
format((PrevBayes*100), digits = 2, nsmall = 2),
format((.data$PrevBayes*100), digits = 2, nsmall = 2),
" (",
format((CrILow*100), digits = 2, nsmall = 2),
format((.data$CrILow*100), digits = 2, nsmall = 2),
" - ",
format((CrIHigh*100), digits = 2, nsmall = 2),
format((.data$CrIHigh*100), digits = 2, nsmall = 2),
")"),
.keep = "unused") %>%
select(-contains("ICC", ignore.case = TRUE)) %>%
Expand Down
14 changes: 7 additions & 7 deletions R/PoolPrev.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ PoolPrev <- function(data,result,poolSize,...,
}

#initialise output object
out <- dplyr::tibble(NumberOfPools = sdata$N,
out <- tibble::tibble(NumberOfPools = sdata$N,
NumberPositive = sum(sdata$Result))

#if there is at least one positive and one negative result
Expand Down Expand Up @@ -318,11 +318,11 @@ print.PoolPrevOutput <- function(x, ...) {
formatted_output <- as.data.frame(
ungroup(x) %>%
mutate(PrevMLE = paste0(" ",
format((PrevMLE*100), digits = 2, nsmall = 2),
format((.data$PrevMLE*100), digits = 2, nsmall = 2),
" (",
format((CILow*100), digits = 2, nsmall = 2),
format((.data$CILow*100), digits = 2, nsmall = 2),
" - ",
format((CIHigh*100), digits = 2, nsmall = 2),
format((.data$CIHigh*100), digits = 2, nsmall = 2),
")"),
.keep = "unused") %>%
rename("PrevMLE % " = "PrevMLE")
Expand All @@ -332,11 +332,11 @@ print.PoolPrevOutput <- function(x, ...) {
formatted_output <- as.data.frame(
formatted_output %>%
mutate(PrevBayes = paste0(" ",
format((PrevBayes*100), digits = 2, nsmall = 2),
format((.data$PrevBayes*100), digits = 2, nsmall = 2),
" (",
format((CrILow*100), digits = 2, nsmall = 2),
format((.data$CrILow*100), digits = 2, nsmall = 2),
" - ",
format((CrIHigh*100), digits = 2, nsmall = 2),
format((.data$CrIHigh*100), digits = 2, nsmall = 2),
")"),
.keep = "unused") %>%
rename("PrevBayes % " = "PrevBayes")
Expand Down
1 change: 1 addition & 0 deletions R/PoolTestR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#' @import methods
#' @import Rcpp
#' @import rstan
#' @importFrom rlang .data
#'
#' @references
#'
Expand Down
32 changes: 16 additions & 16 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extract_matrix_column_ICC <- function(cluster_var, x){
if (cluster_var %in% all_cluster_vars){
# Extract only the columns for this clustering variable
matrix_cols <- x %>%
select(grep("ICC", names(x), value = T))
select(grep("ICC", names(x), value = TRUE))
cluster_cols <- tibble::as_tibble(
lapply(
names(matrix_cols),
Expand Down Expand Up @@ -43,23 +43,23 @@ pretty_format_ICC_column <- function(var_df){
# Record original column names
col_names <- names(var_df)
# Set new column names
names(var_df)[grep("low", names(var_df), ignore.case = T)] <- "low"
names(var_df)[grep("high", names(var_df), ignore.case = T)] <- "high"
names(var_df)[grep("low|high", names(var_df), ignore.case = T, invert = T)] <- "param"
names(var_df)[grep("low", names(var_df), ignore.case = TRUE)] <- "low"
names(var_df)[grep("high", names(var_df), ignore.case = TRUE)] <- "high"
names(var_df)[grep("low|high", names(var_df), ignore.case = TRUE, invert = TRUE)] <- "param"
# Create formatted output column
formatted_df <- var_df %>% mutate(
output = paste0(" ",
custom_round(param),
" (",
custom_round(low),
" - ",
custom_round(high),
")"),
.keep = "none"
)
formatted_df <- var_df %>%
mutate(
output = paste0(" ",
custom_round(.data$param),
" (",
custom_round(.data$low),
" - ",
custom_round(.data$high),
")"),
.keep = "none"
)
# Rename new column as "ICC.<cluster.name>"
names(formatted_df) <-
grep("low|high", col_names, ignore.case = T, invert = T, value = T)
names(formatted_df) <- grep("low|high", col_names, ignore.case = TRUE, invert = TRUE, value = TRUE)
return(formatted_df)
}

Expand Down

0 comments on commit 63a2222

Please sign in to comment.