Skip to content

Commit

Permalink
remove country.column argument
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Nov 19, 2024
1 parent 9d78c5e commit 9190f98
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
9 changes: 4 additions & 5 deletions R/clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ clean <- function(x, ...) UseMethod("clean")
#' @description Cleans survey data to work with the 'contact_matrix' function
#'
#' @param x A [survey()] object
#' @param country.column the name of the country in which the survey participant was interviewed
#' @param participant.age.column the column in `x$participants` containing participants' age
#' @param ... ignored
#' @importFrom data.table fcase
Expand All @@ -19,20 +18,20 @@ clean <- function(x, ...) UseMethod("clean")
#' cleaned <- clean(polymod) # not really necessary as the 'polymod' data set has already been cleaned
#' @autoglobal
#' @export
clean.contact_survey <- function(x, country.column = "country", participant.age.column = "part_age", ...) {
clean.contact_survey <- function(x, participant.age.column = "part_age", ...) {
chkDots(...)

## update country names
if (country.column %in% colnames(x$participants)) {
countries <- x$participants[[country.column]]
if ("country" %in% colnames(x$participants)) {
countries <- x$participants$country
origin.code <- fcase(
all(nchar(as.character(countries)) == 2), "iso2c",
all(nchar(as.character(countries)) == 3), "iso3c",
default = "country.name"
)
converted_countries <- suppressWarnings(countrycode(countries, origin.code, "country.name"))
converted_countries[is.na(converted_countries)] <- as.character(countries[is.na(converted_countries)])
x$participants[, paste(country.column) := factor(converted_countries)]
x$participants[, country := factor(converted_countries)]
}

if (nrow(x$participants) > 0 &&
Expand Down
1 change: 1 addition & 0 deletions R/globals.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxyglobals: do not edit by hand

utils::globalVariables(c(
"country", # <clean.contact_survey>
"..age.unit", # <clean.contact_survey>
"..high", # <clean.contact_survey>
"..low", # <clean.contact_survey>
Expand Down
4 changes: 1 addition & 3 deletions man/clean.Rd

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

0 comments on commit 9190f98

Please sign in to comment.