#' smoke
#'
#' @param data data
#' @param years years
#' @param Year logical
#'
#' @return
#' return three class of smoke
#' - never: smoked less than 100 cigarettes in life
#' - former: smoked less than 100 cigarettes in life and smoke not at all now
#' - now: smoked moth than 100 cigarettes in life and smoke some days or every day
#' @export
#'
attach_smoke <- function(data,years,Year=FALSE){
if (!missing(data)) years <- unique(data$Year)
years <- prepare_years(years)
smq <- nhs_tsv('smq\\.|smq_',cat = FALSE,years=years)
d <- nhs_read(smq,'smq020:smoke','smq040:smoke_now',lower_cd = TRUE,cat = FALSE)
d <- to_NA(d)
d$smoke[d$smoke=='no'] <- 'never'
d$smoke[d$smoke=='yes'] <- 'now'
d$smoke[grepl('not {0,}at {0,}all',d$smoke_now)] <- 'former'
d <- d[,c('Year',"seqn","smoke")]
if (!Year) d <- drop_col(d,'Year')
if (missing(data)) return(d)
dplyr::left_join(data,d,'seqn')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.