From afc261593209676cbf4b5d8cc00f84040360b770 Mon Sep 17 00:00:00 2001
From: gdutz <30431062+gdutz@users.noreply.github.com>
Date: Tue, 24 Aug 2021 11:13:15 +0200
Subject: [PATCH] Change magrittr pipe %>% to native pipe |>

---
 DESCRIPTION       |  3 ++-
 NAMESPACE         |  1 -
 R/leo_svydesign.R | 27 +++++++++++++--------------
 3 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 5039f90..8cdfdc9 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,12 +1,13 @@
 Package: leo
 Type: Package
 Title: Useful functions for LEO surveys
-Version: 0.2.3
+Version: 0.2.4
 Author: Gregor Dutz
 Maintainer: Gregor Dutz <gregor.dutz@uni-hamburg.de>
 Description: Implements simple functions to handle data from two German surveys 
     (LEO 2010 and LEO 2018). This includes correct use of survey weights and
     plausible values using the packages "survey" and "mitools".
+Depends: R (>= 4.1.0)
 License: MIT + file LICENSE
 Encoding: UTF-8
 LazyData: true
diff --git a/NAMESPACE b/NAMESPACE
index 72ed7ba..eb3a794 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,6 +1,5 @@
 # Generated by roxygen2: do not edit by hand
 
 export(leo_svydesign)
-importFrom(magrittr,"%>%")
 importFrom(rlang,":=")
 importFrom(rlang,.data)
diff --git a/R/leo_svydesign.R b/R/leo_svydesign.R
index f23a4d0..8ad3537 100644
--- a/R/leo_svydesign.R
+++ b/R/leo_svydesign.R
@@ -5,7 +5,6 @@
 #' @param replist When true, the function returns an imputation list instead of survey design object.
 #' @return A survey design or imputation list object.
 #'
-#' @importFrom magrittr %>%
 #' @importFrom rlang :=
 #' @importFrom rlang .data
 #' @export
@@ -16,13 +15,13 @@ leo_svydesign <- function(df, survey = "leo2018", replist = FALSE) {
   if (survey == "leo2010" || survey == "leo2018" || survey == "leo2018hoch") {
     if (survey == "leo2010") {
       # remove logits
-      df <- df %>% dplyr::select(-tidyselect::matches("^pv[1-5]$"))
+      df <- df |> dplyr::select(-tidyselect::matches("^pv[1-5]$"))
       # rename variables for pvs and levels
       old=c("pv1_62", "pv2_62", "pv3_62", "pv4_62", "pv5_62",
             "pv1_alphalevel_62", "pv2_alphalevel_62", "pv3_alphalevel_62", "pv4_alphalevel_62", "pv5_alphalevel_62")
       new=c("pv1", "pv2", "pv3", "pv4", "pv5",
             "alpha_pv1", "alpha_pv2", "alpha_pv3", "alpha_pv4", "alpha_pv5")
-      df <- df %>% dplyr::rename_at(dplyr::vars(old), ~new)
+      df <- df |> dplyr::rename_at(dplyr::vars(old), ~new)
     }
 
     # some functions need a helper variable
@@ -32,25 +31,25 @@ leo_svydesign <- function(df, survey = "leo2018", replist = FALSE) {
     lit <- grep("^pv[0-9]+", colnames(df), value = TRUE)
     alp <- grep("^alpha_pv[0-9]+", colnames(df), value = TRUE)
     # column names of all other variables
-    all <- df %>% dplyr::select(-tidyselect::one_of(lit), -tidyselect::one_of(alp))
+    all <- df |> dplyr::select(-tidyselect::one_of(lit), -tidyselect::one_of(alp))
     all <- colnames(all)
     # create list with one pv-variable and one level-variable each (and all other variables)
-    repList <- lit %>%
-      purrr::map(function(x) {dplyr::select(df, all, paste0("alpha_", x), x) %>%
-          dplyr::rename(pv = !!x) %>%
+    repList <- lit |>
+      purrr::map(function(x) {dplyr::select(df, all, paste0("alpha_", x), x) |>
+          dplyr::rename(pv = !!x) |>
           dplyr::rename(alpha_pv = !!paste0("alpha_", x))})
 
     # create further alpha-variables for different analyses
     # alpha3 (three levels): low literate (Alpha 1-3), Alpha 4, above Alpha 4
     # alpha2 (two levels): low literat (Alpha 1-3), high literate (Alpha 4 and above)
     # lowlit (two levels): same as alpha2, but reversed levels
-    repList <- lapply(repList, function(x) {x %>%
-        dplyr::mutate(alpha3 = ifelse(x$alpha_pv > 3, x$alpha_pv, 1)) %>%
-        dplyr::mutate(alpha2 = ifelse(x$alpha_pv > 3, 1, 0)) %>%
-        dplyr::mutate(lowlit = ifelse(x$alpha_pv > 3, 0, 1)) %>%
-        dplyr::mutate(alpha3 = factor(.data$alpha3, labels = (c("a1-3", "a4", "a5")))) %>%
-        dplyr::mutate(alpha2 = factor(.data$alpha2, labels = (c("a1-3", "a4-5")))) %>%
-        dplyr::mutate(lowlit = factor(.data$lowlit, labels = (c("a4-5", "a1-3")))) %>%
+    repList <- lapply(repList, function(x) {x |>
+        dplyr::mutate(alpha3 = ifelse(x$alpha_pv > 3, x$alpha_pv, 1)) |>
+        dplyr::mutate(alpha2 = ifelse(x$alpha_pv > 3, 1, 0)) |>
+        dplyr::mutate(lowlit = ifelse(x$alpha_pv > 3, 0, 1)) |>
+        dplyr::mutate(alpha3 = factor(.data$alpha3, labels = (c("a1-3", "a4", "a5")))) |>
+        dplyr::mutate(alpha2 = factor(.data$alpha2, labels = (c("a1-3", "a4-5")))) |>
+        dplyr::mutate(lowlit = factor(.data$lowlit, labels = (c("a4-5", "a1-3")))) |>
         dplyr::mutate(alpha_pv = labelled::to_factor(.data$alpha_pv))})
 
     # if the imputation list is requested, return it and exit function
-- 
GitLab