From ba3a2928c9d65d52c99a77ebb44603d968249c54 Mon Sep 17 00:00:00 2001 From: "Luke C. Pilling" Date: Mon, 7 Oct 2024 22:29:12 +0100 Subject: [PATCH] v0.2.12 ### Bug fixes * `get_assoc()` - Drop empty factor levels if using haven::as_factor() * `get_assoc()` - Correctly identify covariate variable names when using haven::as_factor() ### Changes * Add light switch to pkgdown site --- DESCRIPTION | 2 +- NEWS.md | 11 +++++++++++ R/get_assoc.R | 4 ++-- README.md | 2 +- _pkgdown.yml | 1 + 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index eab5d49..8384dee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: lukesRlib Title: My library of R functions I sometimes find useful -Version: 0.2.11 +Version: 0.2.12 Authors@R: c(person("Luke", "Pilling", email = "L.Pilling@exeter.ac.uk", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index b18417c..f289acd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# lukesRlib 0.2.12 (7th Oct 2024) + +### Bug fixes +* `get_assoc()` - Drop empty factor levels if using haven::as_factor() +* `get_assoc()` - Correctly identify covariate variable names when using haven::as_factor() + +### Changes +* Add light switch to pkgdown site + + # lukesRlib 0.2.11 (30th Sept 2024) ### Changes @@ -7,6 +17,7 @@ * Update example data categorical variables to include labels * Fix NEWS formatting + # lukesRlib 0.2.10 (6th June 2024) ### Changes diff --git a/R/get_assoc.R b/R/get_assoc.R index aada830..5d4eb0a 100644 --- a/R/get_assoc.R +++ b/R/get_assoc.R @@ -132,7 +132,7 @@ get_assoc = function( # check variables are all in d if (any(! x %in% colnames(d))) stop("Not all exposure variables are in the provided data") if (any(! yy %in% colnames(d))) stop("Not all outcome variables are in the provided data") - z_vars = stringr::str_replace_all(z, " |as.factor\\(|\\)", "") |> + z_vars = stringr::str_replace_all(z, " |as.factor\\(|haven::|\\)", "") |> stringr::str_split_1("\\+|\\*") |> purrr::keep(\(x) stringr::str_length(x)>0) if (any(! z_vars %in% colnames(d))) stop("Not all covariate variables are in the provided data") @@ -240,7 +240,7 @@ get_assoc1 = function( # exposure variable - categorical? # if using haven, mutate the actual data - if (af & !af_base) d = d |> dplyr::mutate( !! rlang::sym(x) := haven::as_factor( !! rlang::sym(x) ) ) + if (af & !af_base) d = d |> dplyr::mutate( !! rlang::sym(x) := droplevels( haven::as_factor( !! rlang::sym(x) ) ) ) if (af) xx = paste0("as.factor(",xx,")") # scale exposure or outcome? diff --git a/README.md b/README.md index ae31995..74a1d2c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ My library of R functions I sometimes find useful -[![](https://img.shields.io/badge/version-0.2.11-informational.svg)](https://github.com/lcpilling/lukesRlib) +[![](https://img.shields.io/badge/version-0.2.12-informational.svg)](https://github.com/lcpilling/lukesRlib) [![](https://img.shields.io/github/last-commit/lcpilling/lukesRlib.svg)](https://github.com/lcpilling/lukesRlib/commits/master) [![](https://img.shields.io/badge/lifecycle-experimental-orange)](https://www.tidyverse.org/lifecycle/#experimental) [![DOI](https://zenodo.org/badge/590063045.svg)](https://zenodo.org/badge/latestdoi/590063045) diff --git a/_pkgdown.yml b/_pkgdown.yml index 2987c68..4cd381e 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,6 +1,7 @@ url: https://lcpilling.github.io/lukesRlib/ template: bootstrap: 5 + light-switch: true authors: Luke Pilling: