From 2aa64aa77b1b2c17aa8c96383d3350038e2fa6e2 Mon Sep 17 00:00:00 2001 From: Rostyslav Vyuha Date: Mon, 25 Nov 2019 10:54:07 -0500 Subject: [PATCH] Revert "Hotfix update" --- .DS_Store | Bin 18436 -> 18436 bytes NEWS.md | 11 +--- R/alcohol.R | 44 +++++++------- R/bmi.R | 64 ++++++++++----------- R/data.R | 79 ++++++++++---------------- R/percent-time-canada.R | 45 +++++++-------- R/respiratory-condition.R | 85 ++++++++++------------------ R/smoking.R | 59 +++++++------------ Vignettes/derivedVariables.Rmd | 4 +- Vignettes/usingcchsflow.Rmd | 2 +- docs/articles/derivedVariables.html | 37 +----------- docs/articles/usingcchsflow.html | 6 +- docs/articles/variableDetails.html | 4 +- docs/articles/variablesSheet.html | 4 +- docs/news/index.html | 28 +++------ 15 files changed, 170 insertions(+), 302 deletions(-) diff --git a/.DS_Store b/.DS_Store index d18c50ea6f4b91fbd99f2e4330ee3ab03a463ea8..9bab5e58baa67218093dce35e0726d552f488f09 100644 GIT binary patch delta 762 zcmb8tT}YEr7zgm@PuAXZ#_Y{~`Ek+Qmu*cmH*0-N*Nh6HW@uRvt>t#{=G>yyG%3AE zh)8L0$byQ9C`yBZNf$v7(tSa@i729|n}~vLj0!rugRUg-TpT$6=RD8F@0{@>#*29L z&?^$_9*eIIgUB@b*?z4*m+jF;(&C*fCPw{cu_bJExT3A3FQ&|xYz+>#uO%3c#LCsn z)fL>#t>RgzR=jPri9t&}xTtov#<|zHim6GZH!p`(F0SUyOwF_20WF)-6JslHQ`8jO zn@Ju`XDU%UU$3Y;SzjT2BCqALm2e{$lg@w$TAgD|1u0ZVP72Wu>ZSvfq9K}~%QQt- z=r%o|S$aax=>@%{S5&6g^npIoC;Cj^Xr6x3FZvCJ8kk{$13vf>Kr`B~37gS@PHe?4 z>_#{CpbtloL_bo<;1mitjS-x)VFHu5gd%R@9`0irvv`U*G3@e*KR&N%+jj0*(2)Hz z6rJv45~;-=k$cA85aH?)3B}6x+PeB+h#S?V(nQgZ;SHRtRT8aIjdaNBGRae^#=1Bc zQIB=3 years ago. +#' @param SMKG09C number of years since quitting smoking. Variable asked to former daily smokers who quit >=3 years ago. #' #' @param SMKG203_cont age started smoking daily. Variable asked to daily smokers. #' @@ -41,38 +36,29 @@ #' #' @examples #' # Using Pack_years_fun() to create pack-years values across CCHS cycles -#' # Pack_years_fun() is specified in variableDetails.csv along with the CCHS variables and cycles -#' # included. +#' # Pack_years_fun() is specified in variableDetails.csv along with the CCHS variables and cycles included. #' -#' # To transform Pack_years_der across cycles, use RecWTable() for each CCHS cycle and specify -#' # Pack_years_der, along with each smoking variable. Then by using bind_rows(), you can combine -#' # Pack_years_der across cycles +#' # To transform Pack_years_der across cycles, use RecWTable() for each CCHS cycle and specify Pack_years_der, along with +#' # each smoking variable. Then by using bind_rows(), you can combine Pack_years_der across cycles #' #' suppressMessages(library(bllflow)) #' library(cchsflow) -#' -#' pack_years2010 <- RecWTable(dataSource = cchs2010, variableDetails = variableDetails, -#' datasetName = "cchs2010", variables = c("SMKDSTY", "DHHGAGE_cont", "SMK_09A_B", "SMKG09C", -#' "SMKG203_cont", "SMKG207_cont", "SMK_204", "SMK_05B", "SMK_208", "SMK_05C", "SMK_01A", -#' "SMKG01C_cont", "Pack_years_der")) -#' +#' pack_years2010 <- RecWTable(dataSource = cchs2010, variableDetails = variableDetails, datasetName = "cchs2010", +#' variables = c("SMKDSTY", "DHHGAGE_cont", "SMK_09A_B", "SMKG09C", "SMKG203_cont", "SMKG207_cont", "SMK_204", "SMK_05B", +#' "SMK_208", "SMK_05C", "SMK_01A", "SMKG01C_cont", "Pack_years_der")) #' head(pack_years2010) #' -#' pack_years2012 <- RecWTable(dataSource = cchs2012, variableDetails = variableDetails, -#' datasetName = "cchs2012", variables = c("SMKDSTY", "DHHGAGE_cont", "SMK_09A_B", "SMKG09C", -#' "SMKG203_cont", "SMKG207_cont", "SMK_204", "SMK_05B", "SMK_208", "SMK_05C", "SMK_01A", -#' "SMKG01C_cont", "Pack_years_der")) -#' +#' pack_years2012 <- RecWTable(dataSource = cchs2012, variableDetails = variableDetails, datasetName = "cchs2012", +#' variables = c("SMKDSTY", "DHHGAGE_cont", "SMK_09A_B", "SMKG09C", "SMKG203_cont", "SMKG207_cont", "SMK_204", "SMK_05B", +#' "SMK_208", "SMK_05C", "SMK_01A", "SMKG01C_cont", "Pack_years_der")) #' tail(pack_years2012) #' #' combined_pack_years <- bind_rows(pack_years2010, pack_years2012) -#' #' head(combined_pack_years) #' tail(combined_pack_years) #' @export Pack_years_fun <- - function(SMKDSTY, DHHGAGE_cont, SMK_09A_B, SMKG09C, SMKG203_cont, SMKG207_cont, SMK_204, SMK_05B, - SMK_208, SMK_05C, SMKG01C_cont, SMK_01A) { + function(SMKDSTY, DHHGAGE_cont, SMK_09A_B, SMKG09C, SMKG203_cont, SMKG207_cont, SMK_204, SMK_05B, SMK_208, SMK_05C, SMKG01C_cont, SMK_01A) { #Time since quit for former daily smokers tsq_ds_fun <- function(SMK_09A_B, SMKG09C) { SMKG09C <- @@ -89,17 +75,14 @@ Pack_years_fun <- # PackYears for Daily Smoker ifelse2(SMKDSTY==1, pmax(((DHHGAGE_cont - SMKG203_cont)*(SMK_204/20)), 0.0137), # PackYears for Occasional Smoker (former daily) - ifelse2(SMKDSTY==2, pmax(((DHHGAGE_cont - SMKG207_cont - tsq_ds)*(SMK_208/20)), 0.0137) + - (pmax((SMK_05B*SMK_05C/30), 1)*tsq_ds), + ifelse2(SMKDSTY==2, pmax(((DHHGAGE_cont - SMKG207_cont - tsq_ds)*(SMK_208/20)), 0.0137) + (pmax((SMK_05B*SMK_05C/30), 1)*tsq_ds), # PackYears for Occasional Smoker (never daily) ifelse2(SMKDSTY==3, (pmax((SMK_05B*SMK_05C/30), 1)/20)*(DHHGAGE_cont - SMKG01C_cont), # PackYears for former daily smoker (non-smoker now) ifelse2(SMKDSTY==4, pmax(((DHHGAGE_cont - SMKG207_cont - tsq_ds)*(SMK_208/20)), 0.0137), - # PackYears for former occasional smoker (non-smoker now) who smoked at least 100 cigarettes - # lifetime + # PackYears for former occasional smoker (non-smoker now) who smoked at least 100 cigarettes lifetime ifelse2(SMKDSTY==5 & SMK_01A==1, 0.0137, - # PackYears for former occasional smoker (non-smoker now) who have not smoked at least 100 - # cigarettes lifetime + # PackYears for former occasional smoker (non-smoker now) who have not smoked at least 100 cigarettes lifetime ifelse2(SMKDSTY==5 & SMK_01A==2, 0.007, # Non-smoker ifelse2(SMKDSTY==6, 0, NA))))))) diff --git a/Vignettes/derivedVariables.Rmd b/Vignettes/derivedVariables.Rmd index 01ae91cc..6bcae5c5 100644 --- a/Vignettes/derivedVariables.Rmd +++ b/Vignettes/derivedVariables.Rmd @@ -65,9 +65,9 @@ data(cchs2010) variables <- read.csv(file.path(getwd(), '../inst/extdata/variables.csv')) variableDetails <- read.csv(file.path(getwd(), '../inst/extdata/variableDetails.csv')) -BMI2003 <- RecWTable(dataSource = cchs2003, variableDetails = variableDetails, datasetName = "cchs2003", log = TRUE, variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_der")) +BMI2003 <- RecWTable(dataSource = cchs2003, variableDetails = variableDetails, datasetName = "cchs2003", log = TRUE, variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_derived")) -BMI2010 <- RecWTable(dataSource = cchs2010, variableDetails = variableDetails, datasetName = "cchs2010", log = TRUE, variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_der")) +BMI2010 <- RecWTable(dataSource = cchs2010, variableDetails = variableDetails, datasetName = "cchs2010", log = TRUE, variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_derived")) ``` Since derived variables are based on previously transformed variables, if you want to only transform your derived variable, you must also specify its base CCHS variables in `RecWTable()` as shown above. So for the derived BMI variable, you will have to also specify the height (`HWTGHTM`) and weight (`HWTGWTK`) variables. diff --git a/Vignettes/usingcchsflow.Rmd b/Vignettes/usingcchsflow.Rmd index f736ca2a..33a64229 100644 --- a/Vignettes/usingcchsflow.Rmd +++ b/Vignettes/usingcchsflow.Rmd @@ -20,7 +20,7 @@ The `RecWTable` and `SetDataLabels` functions are part of the [bllflow](https:// ```{r eval= FALSE} install.packages("devtools") library(devtools) -install_github("Big-Life-Lab/bllflow", ref = "dev") +install_github("Big-Life-Lab/bllflow", ref = "derived-variable-creation") ``` ```{r results= 'hide', message = FALSE, warning=FALSE} diff --git a/docs/articles/derivedVariables.html b/docs/articles/derivedVariables.html index 76a9ff6d..5f16ad21 100644 --- a/docs/articles/derivedVariables.html +++ b/docs/articles/derivedVariables.html @@ -159,7 +159,7 @@

variables <- read.csv(file.path(getwd(), '../inst/extdata/variables.csv')) variableDetails <- read.csv(file.path(getwd(), '../inst/extdata/variableDetails.csv')) -BMI2003 <- RecWTable(dataSource = cchs2003, variableDetails = variableDetails, datasetName = "cchs2003", log = TRUE, variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_der")) +BMI2003 <- RecWTable(dataSource = cchs2003, variableDetails = variableDetails, datasetName = "cchs2003", log = TRUE, variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_derived"))
## [1] "NOTE: 2001 and 2003 CCHS use inches, values converted to meters to 3 decimal points"
 ## [1] "NOTE: 74+ inches converted to 76 inches"
 ## [1] "The variable HWTCGHT was recoded into HWTGHTM for the database cchs2003 the following recodes were made:"
@@ -202,7 +202,7 @@ 

## 1 copy 27.0:135.0 192 ## 2 NA::a 996 0 ## 3 NA::b 997:999 0

-
BMI2010 <- RecWTable(dataSource = cchs2010, variableDetails = variableDetails, datasetName = "cchs2010", log = TRUE, variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_der"))
+
BMI2010 <- RecWTable(dataSource = cchs2010, variableDetails = variableDetails, datasetName = "cchs2010", log = TRUE, variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_derived"))
## [1] "NOTE: Height is a reported in meters from 2005 CCHS onwards"
 ## [1] "The variable HWTGHTM was recoded into HWTGHTM for the database cchs2010 the following recodes were made:"
 ##   valueTo        From rowsRecoded
@@ -224,9 +224,6 @@ 

HWTGWTK - -HWTGBMI_der - @@ -236,9 +233,6 @@

81 - -29.71604 - @@ -247,9 +241,6 @@

81 - -26.35853 - @@ -258,9 +249,6 @@

77 - -31.04056 - @@ -269,9 +257,6 @@

106 - -31.68681 - @@ -280,9 +265,6 @@

72 - -24.14059 - @@ -291,9 +273,6 @@

81 - -33.75843 - @@ -302,9 +281,6 @@

81 - -27.15816 - @@ -313,9 +289,6 @@

NA - -NA - @@ -324,9 +297,6 @@

77 - -25.81702 - @@ -335,9 +305,6 @@

68 - -24.20811 - diff --git a/docs/articles/usingcchsflow.html b/docs/articles/usingcchsflow.html index d2749fb8..b37c524d 100644 --- a/docs/articles/usingcchsflow.html +++ b/docs/articles/usingcchsflow.html @@ -124,7 +124,7 @@

The RecWTable and SetDataLabels functions are part of the bllflow package. RecWTable is used to transform CCHS variables to a common name. SetDataLabels reapplies labels that are lost during the combination process after transforming each CCHS dataset. Install & load the package onto your environment. Since bllflow is still under development and is not on CRAN, you must install the package from Github using the devtools package.

install.packages("devtools")
 library(devtools)
-install_github("Big-Life-Lab/bllflow", ref = "dev")
+install_github("Big-Life-Lab/bllflow", ref = "derived-variable-creation")

library(bllflow)

We use the bind_rows function in the dplyr package to combine datasets.

library(dplyr)
@@ -146,8 +146,8 @@

cchsMock2013 <- data.frame(DHH_SEX = c(1, 2, 1), DHHGAGE = c(2, 1, 1), FVCDTOT = c(25, 15, 6))

Did you notice that the names for the variables are slightly different in the two mock databases? That isn’t a mistake: in the 2001 CCHS the variable for sex is DHHA_SEX and in 2013 CCHS the variable is DHH_SEX.

Don’t worry, cchsflow is here to help! variableDetails.csv contains the rules to harmonize those two variables into a common variable name. In the CCHS, the categories for sex are consistient: 1 = males, 2 = females. variableDetails.csv provides instructions for how to harmonizecategory values or labels, if they change across survey cycles. Variable labes are discussed in later vignettes.

-
-
## `variables.csv` includes 135 variables that can be transformed. The variables are divided into 6 sections, and 38 subjects.
+
+
## `variables.csv` includes 135 variables that can be transformed. The variables are divided into 6 sections, and 38 subjects.

diff --git a/docs/articles/variableDetails.html b/docs/articles/variableDetails.html index 53ef3e1d..cc457a50 100644 --- a/docs/articles/variableDetails.html +++ b/docs/articles/variableDetails.html @@ -119,8 +119,8 @@

variableDetails.csv

Introduction

The variableDetails.csv worksheet contain details for the variables in variables.csv. Information from variableDetails.csv worksheet is used by the RecWTable() function of the bllflow package to transform variables identifed in variableDetails$variableStart to the newly transformed variable in variableDetails$variable.

-
-
#> In the `variableDetails.csv` worksheet there are 1069 rows and 16 columns
+
+
#> In the `variableDetails.csv` worksheet there are 1069 rows and 16 columns

diff --git a/docs/articles/variablesSheet.html b/docs/articles/variablesSheet.html index 7e24ade9..7238d413 100644 --- a/docs/articles/variablesSheet.html +++ b/docs/articles/variablesSheet.html @@ -125,8 +125,8 @@

#> There are 135 variables, grouped in 38 subjects and 6 sections that are available for transformation in CCHS cycles from 2001 to 2014.
#> You can search for variables in the table below. Try searching for the 3 age variables that are used in the Transform CCHS variables vignette. All 3 variables are in the age subject. Try sorting the subject column by clicking the up beside the `subject` heading: the top 3 rows of the table should show the age variables:
 #> [1] "DHHGAGE_A"    "DHHGAGE_B"    "DHHGAGE_cont"
-
- +
+

diff --git a/docs/news/index.html b/docs/news/index.html index 0c6e7852..73599b28 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -141,26 +141,13 @@

Changelog

Source: NEWS.md
-
+

-cchsflow 0.2.2 (Latest build)

+cchsflow 0.2.1 (Latest build)

Features:

    -
  • Updated ref branch of bllflow to match latest version of RecWTable() -
  • -
  • Minor corrections to derived variables article
  • -
-
- -
-

-cchsflow 0.2.1

-
-

-Features:

-
  • Documentation for derived variable functions now available
  • Documentation for derived alcohol variables now available
@@ -169,9 +156,9 @@

cchsflow 0.2.0

-
+

-Features:

+Features:

  • Added Support for derived variables alongside vignettes explaining how to add new variables
  • Added R file with custom functions for derived variables
  • @@ -183,9 +170,9 @@

    cchsflow 0.1.0 (First Version)

    -
    +

    -Features:

    +Features:

    • Added variables.csv that contains list of CCHS variables in cchsflow.
    • Added variableDetails.csv that maps variables across CCHS cycles from 2001-2014
    • @@ -199,8 +186,7 @@

      Contents