Skip to content

Commit

Permalink
Merge pull request #273 from UCD-SERG/263-generalize-attribute-extrac…
Browse files Browse the repository at this point in the history
…tors

263 generalize attribute extractors
  • Loading branch information
d-morrison authored Sep 25, 2024
2 parents c6ef21f + a9008fc commit 7f6b817
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
26 changes: 13 additions & 13 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ 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(get_age,default)
S3method(get_age_var,default)
S3method(get_biomarker_levels,default)
S3method(get_biomarker_names,default)
S3method(get_biomarker_names_var,default)
S3method(get_id,default)
S3method(get_id_var,default)
S3method(get_value,default)
S3method(get_value_var,default)
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(set_age,default)
S3method(set_biomarker_var,default)
S3method(set_id,default)
S3method(set_value,default)
S3method(strata,seroincidence.by)
S3method(summary,pop_data)
S3method(summary,seroincidence)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# serocalculator (development version)

* Generalized `get_()` methods from `pop_data`-specific to `default`.

# serocalculator 1.2.0
* Added `test-summary.pop_data` test

Expand Down
32 changes: 16 additions & 16 deletions R/load_pop_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ get_age <- function(object, ...) {
}

#' @export
get_age.pop_data <- function(object, ...) {
get_age.default <- function(object, ...) {
# get age data
age_data <- object %>% pull(attr(object, "age_var"))

Expand All @@ -36,7 +36,7 @@ get_age_var <- function(object, ...) {
}

#' @export
get_age_var.pop_data <- function(object, ...) {
get_age_var.default <- function(object, ...) {
# get value attribute
age_var <- attributes(object)$age_var

Expand All @@ -48,7 +48,7 @@ get_value <- function(object, ...) {
}

#' @export
get_value.pop_data <- function(object, ...) {
get_value.default <- function(object, ...) {
# get age data
value_data <- object %>% pull(attr(object, "value_var"))

Expand All @@ -60,7 +60,7 @@ get_value_var <- function(object, ...) {
}

#' @export
get_value_var.pop_data <- function(object, ...) {
get_value_var.default <- function(object, ...) {
# get value attribute
value_var <- attributes(object)$value_var

Expand All @@ -72,7 +72,7 @@ get_id <- function(object, ...) {
}

#' @export
get_id.pop_data <- function(object, ...) {
get_id.default <- function(object, ...) {
# get age data
id_data <- object %>% pull(attr(object, "id_var"))

Expand All @@ -84,7 +84,7 @@ get_id_var <- function(object, ...) {
}

#' @export
get_id_var.pop_data <- function(object, ...) {
get_id_var.default <- function(object, ...) {
# get value attribute
id_var <- attributes(object)$id_var

Expand All @@ -96,10 +96,10 @@ set_biomarker_var <- function(object, ...) {
}

#' @export
set_biomarker_var.pop_data = function(object,
biomarker = "antigen_iso",
standardize = TRUE,
...)
set_biomarker_var.default = function(object,

Check warning on line 99 in R/load_pop_data.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/load_pop_data.R,line=99,col=27,[assignment_linter] Use <-, not =, for assignment.
biomarker = "antigen_iso",
standardize = TRUE,
...)
{

Check warning on line 103 in R/load_pop_data.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/load_pop_data.R,line=103,col=1,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line.
if (biomarker %in% colnames(object))
{

Check warning on line 105 in R/load_pop_data.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/load_pop_data.R,line=105,col=3,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line.
Expand Down Expand Up @@ -128,7 +128,7 @@ get_biomarker_levels <- function(object, ...)
}

#' @export
get_biomarker_levels.pop_data <- function(object, ...)
get_biomarker_levels.default <- function(object, ...)
{

Check warning on line 132 in R/load_pop_data.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/load_pop_data.R,line=132,col=1,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line.
attr(object, "antigen_isos")
}
Expand All @@ -138,7 +138,7 @@ get_biomarker_names <- function(object, ...) {
}

#' @export
get_biomarker_names.pop_data <- function(object, ...) {
get_biomarker_names.default <- function(object, ...) {
# get biomarker name data
biomarker_data <- object %>% pull(get_biomarker_names_var(object))

Expand All @@ -150,7 +150,7 @@ get_biomarker_names_var <- function(object, ...) {
}

#' @export
get_biomarker_names_var.pop_data <- function(object, ...) {
get_biomarker_names_var.default <- function(object, ...) {
# get value attribute
biomarker_var <- attributes(object)[["biomarker_var"]]

Expand All @@ -163,7 +163,7 @@ set_age <- function(object, ...) {
}

#' @export
set_age.pop_data <- function(object, age = "Age", standardize = TRUE, ...) {
set_age.default <- function(object, age = "Age", standardize = TRUE, ...) {
# check if age column exists
if (age %in% colnames(object)) {
attr(object, "age_var") <- age
Expand Down Expand Up @@ -214,7 +214,7 @@ set_value <- function(object, ...) {
}

#' @export
set_value.pop_data <- function(object, value = "result", standardize = TRUE, ...) {
set_value.default <- function(object, value = "result", standardize = TRUE, ...) {
# check if value column exists
if (value %in% colnames(object)) {
attr(object, "value_var") <- value
Expand Down Expand Up @@ -261,7 +261,7 @@ set_id <- function(object, ...) {
}

#' @export
set_id.pop_data <- function(object, id = "index_id", standardize = TRUE, ...) {
set_id.default <- function(object, id = "index_id", standardize = TRUE, ...) {
# check if id column exists
if (id %in% colnames(object)) {
attr(object, "id_var") <- id
Expand Down

0 comments on commit 7f6b817

Please sign in to comment.