From bca7dccc768f329a1c8b38d85a8fc9922c715742 Mon Sep 17 00:00:00 2001 From: Gregor de Cillia Date: Wed, 27 May 2020 15:33:19 +0200 Subject: [PATCH] remove dependencies (dplyr, matrixStats) part of #28 --- DESCRIPTION | 2 +- NAMESPACE | 2 -- R/demo.eusilc.R | 8 ++++---- R/helpers.R | 10 ++++++++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2efd398..dca2c99 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ Description: Calculate point estimates and their standard errors in complex hous Encoding: UTF-8 LazyData: true License: GPL (>= 2) -Imports: Rcpp (>= 0.12.12),data.table,matrixStats, ggplot2, laeken, methods, dplyr +Imports: Rcpp (>= 0.12.12),data.table,ggplot2,laeken,methods LinkingTo: Rcpp URL: https://github.com/statistikat/surveysd BugReports: https://github.com/statistikat/surveysd/issues diff --git a/NAMESPACE b/NAMESPACE index 9c5ec24..0711afb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,7 +24,6 @@ import(data.table) import(ggplot2) importFrom("graphics","plot") importFrom("laeken","weightedMedian") -importFrom("matrixStats","rowProds") importFrom("methods","formalArgs") importFrom("stats","as.formula") importFrom("stats","formula") @@ -36,5 +35,4 @@ importFrom("utils","data") importFrom("utils","find") importFrom("utils","head") importFrom("utils","tail") -importFrom(dplyr,recode) useDynLib(surveysd) diff --git a/R/demo.eusilc.R b/R/demo.eusilc.R index 56022f2..e89b895 100644 --- a/R/demo.eusilc.R +++ b/R/demo.eusilc.R @@ -28,7 +28,6 @@ #' * `povertyRisk`. Logical variable determining whether a respondent is at risk #' of poverty #' -#' @importFrom dplyr recode #' @examples #' demo.eusilc(n = 1, prettyNames = TRUE)[, c(1:8, 26, 28:30)] #' @export @@ -71,9 +70,10 @@ demo.eusilc <- function(n = 8, prettyNames = FALSE) { data.table::setnames(eusilc, "rb090", "gender") data.table::setnames(eusilc, "pb220a", "citizenship") data.table::setnames(eusilc, "pl030", "ecoStat") - eusilc[, ecoStat := dplyr::recode( - ecoStat, `1` = "full time", `2` = "part time", `3` = "unemployed", - `4` = "education", `5` = "retired", `6` = "disabled", `7` = "domestic")] + eusilc[, ecoStat := factor(ecoStat, labels = c( + "full time", "part time", "unemployed", + "education", "retired", "disabled", "domestic" + ))] data.table::setnames(eusilc, "rb050", "pWeight") data.table::setnames(eusilc, "povmd60", "povertyRisk") eusilc[, povertyRisk := as.logical(povertyRisk)] diff --git a/R/helpers.R b/R/helpers.R index ae27468..54b8573 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -6,12 +6,18 @@ #' @importFrom "graphics" "plot" #' @importFrom "stats" "as.formula" "na.omit" "quantile" "sd" "xtabs" "formula" #' @importFrom "utils" "data" "find" "tail" "head" -#' @importFrom "matrixStats" "rowProds" #' @importFrom "laeken" "weightedMedian" #' @importFrom "methods" "formalArgs" #' @useDynLib surveysd - +rowProds <- function(x) { + n <- nrow(x) + y <- double(length = n) + for (ii in seq_len(n)) { + y[ii] <- prod(x[ii, , drop = TRUE], na.rm = na.rm) + } + y +} dt.eval <- function(..., env = parent.frame()) {