Skip to content

Commit

Permalink
clear conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisorwa committed Oct 4, 2024
2 parents c53b45b + 9748d7b commit 470059f
Show file tree
Hide file tree
Showing 72 changed files with 11,905 additions and 848 deletions.
7 changes: 7 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ allpopsamples_hlye.csv$
^CRAN-SUBMISSION$
^README\.qmd$
^codecov\.yml$
^_quarto\.yml$
^\.lintr$
^vignettes$
^vignettes/\.quarto$
^vignettes/methodology\.qmd$
^\.quarto$
^man/df_to_array\.Rd$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ serocalculator*.tar.gz
serocalculator*.tgz
README.html
README_files

/.quarto/
2 changes: 2 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
linters: linters_with_defaults() # see vignette("lintr")
encoding: "UTF-8"
15 changes: 12 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: serocalculator
Title: Estimating Infection Rates from Serological Data
Version: 1.2.0.9009
Version: 1.2.0.9014
Authors@R: c(
person("Peter", "Teunis", , "p.teunis@emory.edu", role = c("aut", "cph"),
comment = "Author of the method and original code."),
Expand Down Expand Up @@ -41,22 +41,31 @@ Imports:
utils
Suggests:
bookdown,
devtag (>= 0.0.0.9000),
DT,
fs,
ggbeeswarm,
knitr,
pak,
parallel,
readr,
quarto,
rmarkdown,
spelling,
ssdtools (>= 1.0.6.9016),
testthat (>= 3.0.0),
tidyverse
tidyverse,
qrcode
LinkingTo:
Rcpp
Config/testthat/edition: 3
Config/Needs/build: moodymudskipper/devtag
Encoding: UTF-8
Language: en-US
LazyData: true
NeedsCompilation: no
Roxygen: list(markdown = TRUE)
Remotes:
bcgov/ssdtools,
moodymudskipper/devtag
Roxygen: list(markdown = TRUE, roclets = c("collate", "rd", "namespace", "devtag::dev_roclet"))
RoxygenNote: 7.3.2
16 changes: 2 additions & 14 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,18 @@ S3method(autoplot,pop_data)
S3method(autoplot,seroincidence)
S3method(autoplot,seroincidence.by)
S3method(autoplot,summary.seroincidence.by)
S3method(get_age,pop_data)
S3method(get_age_var,pop_data)
S3method(get_biomarker_levels,pop_data)
S3method(get_biomarker_names,pop_data)
S3method(get_biomarker_names_var,pop_data)
S3method(get_id,pop_data)
S3method(get_id_var,pop_data)
S3method(get_value,pop_data)
S3method(get_value_var,pop_data)
S3method(print,seroincidence)
S3method(print,seroincidence.by)
S3method(print,summary.pop_data)
S3method(print,summary.seroincidence.by)
S3method(set_age,pop_data)
S3method(set_biomarker_var,pop_data)
S3method(set_id,pop_data)
S3method(set_value,pop_data)
S3method(strata,seroincidence.by)
S3method(summary,pop_data)
S3method(summary,seroincidence)
S3method(summary,seroincidence.by)
export(as_curve_params)
export(as_noise_params)
export(as_pop_data)
export(autoplot)
export(check_pop_data)
export(est.incidence)
export(est.incidence.by)
Expand All @@ -39,7 +27,7 @@ export(fdev)
export(getAdditionalData)
export(get_additional_data)
export(graph.curve.params)
export(graph.loglik)
export(graph_loglik)
export(llik)
export(load_curve_params)
export(load_noise_params)
Expand Down
22 changes: 21 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

## New features

* Updated `simulate_xsectionalData.Rmd()` (linting, removing deprecated functions).

* Added default value for `antigen_isos` argument in `log_likelihood()` (#286)

* Updated enteric fever example article with upgraded code and visualizations (#290)

* Added `Methodology` vignette (#284, #302)

* Added template for reporting Issues
(from `usethis::use_tidy_issue_template()`) (#270)

Expand All @@ -15,11 +23,23 @@

## Developer-facing changes

* Updated GitHub Action files and reformatted `DESCRIPTION` (#268)
* initialized [`lintr`](https://lintr.r-lib.org/) with `lintr::use_lint()` (#278)

* created unit test for `df_to_array()` (#276)

* fixed `dplyr::select()` deprecation warning in `df_to_array()` (#276)

* Added `devtag` to package (using `devtag::use_devtag()`) (#292)
* Added `@dev` tag to `?df_to_array()` (#292)

* Generalized `get_()` and `set_()` methods to be general-purpose
(no S3 class-specific methods needed yet) (#274).

* Updated GitHub Action files and reformatted `DESCRIPTION` (#268)
* Added `.gitattributes` file (<https://git-scm.com/docs/gitattributes>)
copied from <https://github.com/tidyverse/ggplot2>

* Added QR code to `README.qmd`
* Added additional automated checks through
[GitHub actions](https://docs.github.com/en/actions),
including:
Expand Down
26 changes: 16 additions & 10 deletions R/as_curve_params.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#' Load antibody decay curve parameter
#'
#' @param data a [data.frame()] or [tibble::tbl_df]
#' @param antigen_isos [character()] vector of antigen isotypes to be used in analyses
#' @returns a `curve_data` object (a [tibble::tbl_df] with extra attribute `antigen_isos`)
#' @param antigen_isos a [character()] vector of antigen isotypes
#' to be used in analyses
#' @returns a `curve_data` object
#' (a [tibble::tbl_df] with extra attribute `antigen_isos`)
#' @export
#' @examples
#' library(magrittr)
Expand All @@ -14,8 +16,7 @@
#' print(curve_data)
as_curve_params <- function(data, antigen_isos = NULL) {

if(!is.data.frame(data))
{
if (!is.data.frame(data)) {
cli::cli_abort(
class = "not data.frame",
message = c(
Expand All @@ -31,16 +32,18 @@ as_curve_params <- function(data, antigen_isos = NULL) {
data %>%
tibble::as_tibble()

# check if object has expected columns:

# define curve columns
curve_cols <- c("antigen_iso", "y0", "y1", "t1", "alpha", "r")

# check if object is curve (with columns)
if (!all(is.element(curve_cols, curve_data %>% names()))) {
# get columns from provided data
data_cols <- data %>% names()
# get columns from provided data
data_cols <- data %>% names()

# get any missing column(s)
missing_cols <- setdiff(x = curve_cols, y = data_cols)

# get any missing column(s)
missing_cols <- setdiff(x = curve_cols, y = data_cols)
if (length(missing_cols) > 0) {

cli::cli_abort(
class = "not curve_params",
Expand All @@ -67,5 +70,8 @@ as_curve_params <- function(data, antigen_isos = NULL) {
# assign antigen attribute
attr(curve_data, "antigen_isos") <- antigen_isos

curve_data <- curve_data %>%
set_biomarker_var(biomarker = "antigen_iso", standardize = FALSE)

return(curve_data)
}
191 changes: 191 additions & 0 deletions R/class_attributes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
get_age_var <- function(object, ...) {
age_var <- attributes(object)$age_var
return(age_var)
}

get_age <- function(object, ...) {
age_var <- object %>% get_age_var()
age_data <- object %>% pull(age_var)
return(age_data)
}

get_value_var <- function(object, ...) {
value_var <- attributes(object)$value_var
return(value_var)
}

get_value <- function(object, ...) {
value_var_name <- object %>% get_value_var()
value_data <- object %>% pull(value_var_name)
return(value_data)
}

get_id_var <- function(object, ...) {
id_var <- attributes(object)$id_var
return(id_var)
}

get_id <- function(object, ...) {
id_var_name <- object %>% get_id_var()
id_data <- object %>% pull(id_var_name)
return(id_data)
}

get_biomarker_levels <- function(object, ...) {
attr(object, "antigen_isos")
}

get_biomarker_names_var <- function(object, ...) {
# get value attribute
biomarker_var <- attributes(object)[["biomarker_var"]]

return(biomarker_var)
}

get_biomarker_names <- function(object, ...) {
# get biomarker name data
biomarker_names_var <- get_biomarker_names_var(object)
biomarker_data <- object %>% pull(biomarker_names_var)

return(biomarker_data)
}


set_age <- function(object,
age = "Age",
standardize = TRUE,
...) {
# check if age column exists
if (age %in% colnames(object)) {
attr(object, "age_var") <- age
} else {
cli::cli_warn(class = "missing variable",
'The specified `age` column "{age}" does not exist.')

# search age variable from object
age_var <-
grep(
x = colnames(object),
value = TRUE,
pattern = age,
ignore.case = TRUE
)

if (length(age_var) == 1) {
attr(object, "age_var") <- age_var

# create warning when using searched age instead of provided age
cli::cli_inform('Proceeding to use "{.var {age_var}}"')
} else if (length(age_var) == 0) {
cli::cli_abort("No similar column name was detected.")
} else if (length(age_var) > 1) {
cli::cli_warn("Multiple potential matches found: {.var {age_var}}")
cli::cli_warn("Using first match: {.var {age_var[1]}}")
attr(object, "age_var") <- age_var[1]
} else {
cli::cli_abort("{.code length(age_var)} = {.val {length(age_var)}}")
}
}

if (standardize) {
object <- object %>%
rename(c("age" = attr(object, "age_var")))

# set age attribute
attr(object, "age_var") <- "age"
}

return(object)
}


set_value <- function(object,
value = "result",
standardize = TRUE,
...) {
# check if value column exists
if (value %in% colnames(object)) {
attr(object, "value_var") <- value
} else {
cli::cli_warn('The specified `value` column "{.var {value}}"
does not exist.')

# search value variable from pop_data
value_var <-
grep(
x = colnames(object),
value = TRUE,
pattern = value,
ignore.case = TRUE
)

if (length(value_var) == 1) {
attr(object, "value_var") <- value_var

# create warning when using searched age instead of provided age
cli::cli_inform('Proceeding to use "{.var {value_var}}"')
} else if (length(value_var) == 0) {
cli::cli_abort("No similar column name was detected.")
} else {
# i.e. if (length(value_var) > 1)
cli::cli_warn("Multiple potential matches found: {.var {value_var}}")
cli::cli_inform("Using first match: {.var {value_var[1]}}")
attr(object, "value_var") <- value_var[1]
}
}

if (standardize) {
object <- object %>%
rename(c("value" = attr(object, "value_var")))

# set id attribute
attr(object, "value_var") <- "value"
}

return(object)
}

set_id <- function(object,
id = "index_id",
standardize = TRUE,
...) {
# check if id column exists
if (id %in% colnames(object)) {
attr(object, "id_var") <- id
} else {
cli::cli_warn("The specified {.var id} column {.val {id}} does not exist.")

# search id variable from object
id_var <-
grep(
x = colnames(object),
value = TRUE,
pattern = id,
ignore.case = TRUE
)

if (length(id_var) == 1) {
attr(object, "id_var") <- id_var

# create warning when using searched id instead of provided id
cli::cli_inform('Proceeding to use "{id_var}"')
} else if (length(id_var) == 0) {
cli::cli_abort("No similar column name was detected.")
} else {
# if (length(id_var) > 1)
cli::cli_warn("Multiple potential matches found: {.var {id_var}}")
cli::cli_inform("Using first match: {.var {id_var[1]}}")
attr(object, "id_var") <- id_var[1]
}
}

if (standardize) {
object <- object %>%
rename(c("id" = attr(object, "id_var")))

# set id attribute
attr(object, "id_var") <- "id"
}

return(object)
}
Loading

0 comments on commit 470059f

Please sign in to comment.