Skip to content

Commit

Permalink
new function as_popim_vacc_activities()
Browse files Browse the repository at this point in the history
  • Loading branch information
tinigarske committed Mar 21, 2024
1 parent bb71890 commit 2b11428
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 12 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(apply_vacc)
export(as_popim_pop)
export(as_vacc_activities)
export(calc_pop_immunity)
export(complete_vacc_activities)
export(plot_immunity)
Expand Down
12 changes: 7 additions & 5 deletions R/popim_population.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ read_popim_pop <- function(file) {
##' columns and data ranges), and if so converts it to a
##' `popim_population` object and returns this.
##'
##' The input dataframe has to have at least the columns region, age,
##' and year. The output popim_population object is generated via
##' expand.grid to have consecutive year and age ranges that are
##' The input dataframe has to have at least the columns `region`,
##' `age`, and `year`. The output popim_population object is generated
##' via expand.grid to have consecutive year and age ranges that are
##' identical for all regions.
##'
##' If the input dataframe contains a column `pop_size`, this must be
Expand All @@ -151,9 +151,11 @@ read_popim_pop <- function(file) {
##' numeric, with values between 0 and 1. If it is missing, this
##' column is generated and initialised to 0.
##'
##' Any further colunms are simply carried over into the popim_population object.
##' Any further colunms are simply carried over into the
##' popim_population object.
##'
##' @param df a dataframe with at least columns region, age, year and pop_size.
##' @param df a dataframe with at least columns region, age, year and
##' pop_size.
##' @return an object of class `popim_population`
##' @author Tini Garske
##' @export
Expand Down
25 changes: 23 additions & 2 deletions R/popim_vacc_activities.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,31 @@ read_vacc_activities <- function(file) {
stop(sprintf("%s does not exist", file), call. = FALSE)

df <- utils::read.csv(file, stringsAsFactors = FALSE)
class(df) <- c("popim_vacc_activities", "data.frame")
df <- as_vacc_activities(df)
df
}

validate_vacc_activities(df)
##' Generate a `popim_vacc_activites object from a dataframe
##'
##' Checks if the dataframe is suitable (i.e., contains appropriate
##' columns and data ranges), and if so converts it to a
##' `popim_vacc_activities` object and returns this.
##'
##' The input dataframe has to have at least teh columns `region`,
##' `year`, `age_first`, `age_last`, `coverage`, `doses` and
##' `targeting`. Any further columns are simply carried over into the
##' `popim_vacc_activities` object.
##'
##' @param df dataframe to be converted to class
##' `popim_vacc_activities`
##' @return an object of class `popim_vacc_activities`
##' @author Tini Garske
##' @seealso [popim_vacc_activities()] for details of the S3 class.
##' @export
as_vacc_activities <- function(df) {

class(df) <- c("popim_vacc_activities", "data.frame")
validate_vacc_activities(df)
df
}

Expand Down
12 changes: 7 additions & 5 deletions man/as_popim_pop.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions man/as_vacc_activities.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b11428

Please sign in to comment.