Skip to content

Commit

Permalink
Merge pull request #24 from Big-Life-Lab/cran-hotfix
Browse files Browse the repository at this point in the history
Cran hotfix
  • Loading branch information
wyusuf068 authored Jan 8, 2020
2 parents 88d4b9f + ca0bddf commit 085d222
Show file tree
Hide file tree
Showing 116 changed files with 2,178 additions and 778 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
^cran-comments\.md$
^README.html
^CRAN-RELEASE$
^CODE_OF_CONDUCT.md
25 changes: 25 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contributor Code of Conduct

As contributors and maintainers of this project, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating documentation,
submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for
everyone, regardless of level of experience, gender, gender identity and expression,
sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.

Examples of unacceptable behavior by participants include the use of sexual language or
imagery, derogatory comments or personal attacks, trolling, public or private harassment,
insults, or other unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments,
commits, code, wiki edits, issues, and other contributions that are not aligned to this
Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
from the project team.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the Contributor Covenant
(http://contributor-covenant.org), version 1.0.0, available at
http://contributor-covenant.org/version/1/0/0/
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ This page outlines how to contribute to the `cchsflow` package.

### Transforming existing CCHS variables

Using the naming conventions described in the [`variables.csv`](https://big-life-lab.github.io/cchsflow/articles/variablesSheet.html) and [`variableDetails.csv`](https://big-life-lab.github.io/cchsflow/articles/variableDetails.html) you can add more CCHS variables that can be transformed and harmonized across cycles.
Using the naming conventions described in the [`variables.csv`](https://big-life-lab.github.io/cchsflow/articles/variables_sheet.html) and [`variable_details.csv`](https://big-life-lab.github.io/cchsflow/articles/variable_details.html) you can add more CCHS variables that can be transformed and harmonized across cycles.

### Creating a derived variable

You will first need to create a custom function that will carry out the necessary transformations needed for your derived variable. You will then need to specify your derived variable on `variables.csv` and `variableDetails.csv`. For more information, [click here]('~../Vignettes/howtoaddvariables.html').
You will first need to create a custom function that will carry out the necessary transformations needed for your derived variable. You will then need to specify your derived variable on `variables.csv` and `variable_details.csv`. For more information, [click here](https://big-life-lab.github.io/cchsflow/articles/how_to_add_variables.html).

## Documentation

Expand All @@ -37,11 +37,11 @@ bug, you may also create an associated issue. If possible, try to illustrate you
## Pull request
* Please create a Git branch for each pull request (PR). [Click here](https://help.github.com/en/articles/creating-a-pull-request-from-a-fork) for information on how to create a PR.
* Your contributed code should roughly follow the tidyverse [style guide](http://style.tidyverse.org). _Exceptions_ from this guide: function names in PascalCase (e.g. NewFunction()) and variable names as camelCase (e.g newVariable <- "hi").
* Your contributed code should roughly follow the tidyverse [style guide](http://style.tidyverse.org).
* cchsflow uses [roxygen2](https://cran.r-project.org/package=roxygen2), with
[Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/markdown.html),
[Markdown syntax](https://bookdown.org/yihui/rmarkdown/markdown-syntax.html),
for documentation.
* cchsflow uses [testthat](https://cran.r-project.org/package=testthat) (TBA). Adding tests to the PR makes it easier for me to merge your PR into the code base.
* cchsflow uses [testthat](https://cran.r-project.org/package=testthat). Adding tests to the PR makes merging the PR into the code base less prone to bugs.
* If your PR is a user-visible change, you may add a bullet to the top of `NEWS.md` describing the changes made. You may optionally add your GitHub username, and links to relevant issue(s)/PR(s).

## Code of Conduct
Expand Down
17 changes: 12 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: cchsflow
Type: Package
Title: Transforming and Harmonizing CCHS Variables
Version: 1.0.1
Version: 1.1.0
Authors@R: c(
person(given = "Doug",
family = "Manuel",
role = c("aut"),
role = c("aut", "cph"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-0912-0845")),
person(given = "Warsame",
Expand All @@ -23,19 +23,26 @@ Authors@R: c(
person(given = "Yulric",
family = "Sequeira",
role = c("ctb"),
email = "[email protected]"))
email = "[email protected]"),
person(given = "The Ottawa Hospital",
role = c("cph"),
email = "[email protected]"))
Depends:
R (>= 3.2),
haven (>= 1.1.2),
dplyr (>= 0.8.2),
sjlabelled (>= 1.0.17),
stringr (>= 1.2.0),
magrittr
Description: Variable transformation and harmonization for the Canadian Community Health Survey from
2001 to 2014.
Description: Variable transformation and harmonization of the Canadian Community Health Survey (CCHS) from
2001 to 2014. This is useful for researchers interested in using Canadian population health data
across multiple years as it helps combine variables. This package relies on rec_with_table() which was based off sjmisc rec().
Lüdecke D (2018). sjmisc: Data and Variable Transformation Functions. Journal of Open Source Software, 3(26), 754. doi: 10.21105/joss.00754.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
URL: https://github.com/Big-Life-Lab/cchsflow
BugReports: https://github.com/Big-Life-Lab/cchsflow/issues
RoxygenNote: 7.0.2
Suggests:
testthat (>= 2.1.0)
29 changes: 28 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
# cchsflow 1.0.1 (Latest build)
# cchsflow 1.1.0 (Latest build)
2020-01-08

## Breaking changes

* Changed `data_source` parameter in `rec_with_table()` to `data`.

* Changed order of parameters to have `variables` after `dataset_name`.

## New features

- Added warnings to `set_data_labels()` when a variable is present in details
but missing in variables and vice versa.
- Added automated testing for functions

## Minor improvements and bug fixes

- Updated `DESCRIPTION` to expand description of package and added The Ottawa
Hospital as author.
- Refactored `age_cat_fun()` to account for age below 0 and include warning
messages for respiratory functions.
- Added trailing white space removal to `set_data_labels()`.
- Added trailing white space removal to startVariable during `rec_with_table()`.
- Added missing contributing code of conduct page.
- Minor formatting changes on vignettes and `README.md` for better clarity.
- Fixed broken links in articles.

# cchsflow 1.0.1
2019-12-19

## Features
Expand Down
21 changes: 19 additions & 2 deletions R/age-categorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,29 @@
#' CCHS cycles. As such, a continuous age variable (DHHGAGE_cont) was created
#' that harmonized age across all CCHS cycles by taking the midpoint of each
#' age category. This new age variable (DHHGAGE_C) categorizes age based on the
#' categories used in CCHS cycles from 2007 to 2014.
#' categories used in CCHS cycles from 2007 to 2014.
#'
#' @param DHHGAGE_cont continuous age variable
#'
#'
#' @return a categorical age variable (DHHGAGE_C)
#'
#' @examples
#' # Using age_cat_fun() to create categorical age values from DHHGAGE_cont
#' # age_cat_fun() is specified in variable_details.csv along with the CCHS
#' # variables and cycles included.
#'
#' # To generate DHHGAGE_C in a cycle, use rec_with_table() and specify
#' # DHHGAGE_C along with DHHGAGE_cont.
#'
#' library(cchsflow)
#'
#' cat_age2010 <- rec_with_table(
#' data = cchs2010, variable_details =
#' variable_details, dataset_name = "cchs2010", variables = c(
#' "DHHGAGE_cont", "DHHGAGE_C"
#' )
#' )
#'
#' @export
age_cat_fun <- function(DHHGAGE_cont) {
if_else2(
Expand Down
16 changes: 16 additions & 0 deletions R/alcohol.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#' @param ALWDWKY cchsflow variable name for number of drinks consumed in the
#' past week
#'
#' @examples
#' library(cchsflow)
#' ?ALWDWKY
#'
#' @export
ALWDWKY <- function(ALWDWKY) {
# this is for documentation purposes only
Expand All @@ -34,6 +38,10 @@ ALWDWKY <- function(ALWDWKY) {
#'
#' @param ALWDDLY cchsflow variable name for average daily alcohol consumption
#'
#' @examples
#' library(cchsflow)
#' ?ALWDDLY
#'
#' @export
ALWDDLY <- function(ALWDDLY) {
# this is for documentation purposes only
Expand Down Expand Up @@ -65,6 +73,10 @@ ALWDDLY <- function(ALWDDLY) {
#'
#' @param ALCDTYP cchsflow variable name for type of drinker
#'
#' @examples
#' library(cchsflow)
#' ?ALCDTYP
#'
#' @export
ALCDTYP <- function(ALCDTYP) {
# this is for documentation purposes only
Expand All @@ -91,6 +103,10 @@ ALCDTYP <- function(ALCDTYP) {
#'
#' @param ALCDTTM cchsflow variable name for type of drinker (12 months)
#'
#' @examples
#' library(cchsflow)
#' ?ALCDTTM
#'
#' @export
ALCDTTM <- function(ALCDTTM) {
# this is for documentation purposes only
Expand Down
4 changes: 2 additions & 2 deletions R/bmi.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#'
#' library(cchsflow)
#' bmi2010 <- rec_with_table(
#' data_source = cchs2010, variable_details =
#' data = cchs2010, variable_details =
#' variable_details, dataset_name = "cchs2010", variables = c(
#' "HWTGHTM",
#' "HWTGWTK", "HWTGBMI_der"
Expand All @@ -62,7 +62,7 @@
#' head(bmi2010)
#'
#' bmi2012 <- rec_with_table(
#' data_source = cchs2012, variable_details =
#' data = cchs2012, variable_details =
#' variable_details, dataset_name = "cchs2012", variables = c(
#' "HWTGHTM",
#' "HWTGWTK", "HWTGBMI_der"
Expand Down
41 changes: 41 additions & 0 deletions R/label-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@
#' @param data_to_label newly transformed dataset
#' @param variable_details variable_details.csv
#' @param variables_sheet variables.csv
#'
#' @return labeled data_to_label
#'
#' @examples
#' library(cchsflow)
#' library(sjlabelled)
#' bmi2010 <- rec_with_table(
#' data = cchs2010, variable_details =
#' variable_details, dataset_name = "cchs2010", variables = c(
#' "HWTGHTM",
#' "HWTGWTK", "HWTGBMI_der"
#' )
#' )
#'
#' bmi2012 <- rec_with_table(
#' data = cchs2012, variable_details =
#' variable_details, dataset_name = "cchs2012", variables = c(
#' "HWTGHTM",
#' "HWTGWTK", "HWTGBMI_der"
#' )
#' )
#'
#' combined_bmi <- bind_rows(bmi2010, bmi2012)
#'
#' get_label(combined_bmi)
#'
#' labeled_combined_data <- set_data_labels(combined_bmi,
#' variable_details,
#' variables)
#'
#' get_label(labeled_combined_data)
#' @export
set_data_labels <-
function(data_to_label,
Expand All @@ -15,6 +46,8 @@ set_data_labels <-
variable_names <- unique(colnames(data_to_label))
# extract only relevant variable info
if (!is.null(variable_details)) {
variable_details[[pkg.globals$argument.Variables]] <- sapply(
variable_details[[pkg.globals$argument.Variables]], trimws)
variable_details <-
variable_details[variable_details[[pkg.globals$argument.Variables]]
%in% variable_names, ]
Expand All @@ -25,6 +58,8 @@ set_data_labels <-
}
}
if (!is.null(variables_sheet)) {
variables_sheet[[pkg.globals$argument.Variables]] <- sapply(
variables_sheet[[pkg.globals$argument.Variables]], trimws)
variables_sheet <-
variables_sheet[variables_sheet[[pkg.globals$argument.Variables]] %in%
variable_names, ]
Expand Down Expand Up @@ -137,6 +172,12 @@ create_label_list_element <- function(variable_rows) {
#' @return Returns labeled data
label_data <- function(label_list, data_to_label) {
for (variable_name in names(label_list)) {
if (is.na(label_list[[variable_name]]$type)) {
warning(paste(variable_name,
"is missing from variable_details or variables
(if it was also passed) please verify correct spelling"))
next()
}
if (label_list[[variable_name]]$type == pkg.globals$argument.CatType) {
if (class(data_to_label[[variable_name]]) != "factor") {
data_to_label[[variable_name]] <-
Expand Down
20 changes: 8 additions & 12 deletions R/percent-time-canada.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#'
#' library(cchsflow)
#' pct_time2010 <- rec_with_table(
#' data_source = cchs2010, variable_details = variable_details,
#' data = cchs2010, variable_details = variable_details,
#' dataset_name = "cchs2010", variables = c(
#' "DHHGAGE_cont", "SDCGCBG",
#' "SDCGRES", "pct_time_der"
Expand All @@ -43,7 +43,7 @@
#' head(pct_time2010)
#'
#' pct_time2012 <- rec_with_table(
#' data_source = cchs2012, variable_details = variable_details,
#' data = cchs2012, variable_details = variable_details,
#' dataset_name = "cchs2012", variables = c(
#' "DHHGAGE_cont", "SDCGCBG",
#' "SDCGRES", "pct_time_der"
Expand All @@ -66,15 +66,11 @@
#' @export
pct_time_fun <-
function(DHHGAGE_cont, SDCGCBG, SDCGRES) {
SDCGRES_fun <- function(SDCGRES) {
if_else2(
SDCGRES == 1, 4.5,
if_else2(SDCGRES == 2, 15, NA)
)
if (is_equal(SDCGCBG, 1)) {
return(1)
}
SDCGRES <- SDCGRES_fun(SDCGRES)
if_else2(
SDCGCBG == 1, 1,
if_else2(SDCGCBG == 2, (SDCGRES / DHHGAGE_cont), NA)
)
DHHGAGE_cont <- if_else2(DHHGAGE_cont > 0, DHHGAGE_cont, return(NA))
SDCGRES <- if_else2(SDCGRES == 1, 4.5,
if_else2(SDCGRES == 2, 15, return(NA)))
if_else2(SDCGCBG == 2, (SDCGRES / DHHGAGE_cont), NA)
}
Loading

0 comments on commit 085d222

Please sign in to comment.