Skip to content

Commit

Permalink
update of add from lup
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewphamilton committed Nov 24, 2024
1 parent c4d8f8c commit 987ea62
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ Description: ready4use provides a set of tools for managing data for
of the ready4use package has been made available as part of the
process of testing and documenting the package. If you have any
questions, please contact the authors (matthew.hamilton1@monash.edu).
License: GPL-3 + file LICENSE
License: GPL-3
URL: https://ready4-dev.github.io/ready4use/,
https://github.com/ready4-dev/ready4use, https://www.ready4-dev.com/
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Suggests:
knitr,
pkgload,
rmarkdown,
testthat
VignetteBuilder: knitr
Expand Down
14 changes: 10 additions & 4 deletions R/fn_add.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,23 @@ add_from_lup_prototype <- function (data_tb, arrange_1L_chr = character(0), excl
method_1L_chr = method_1L_chr)
data_tb <- data_tb %>% dplyr::left_join(distinct_tb)
}
if (type_1L_chr == "self") {
if (type_1L_chr %in% c("self", "impute")) {
if (identical(vars_chr, character(0))) {
vars_chr <- setdiff(names(data_tb), c(match_var_nm_1L_chr,
exclude_chr))
}
data_tb <- purrr::reduce(vars_chr, .init = data_tb, ~{
distinct_tb <- .x %>% dplyr::select(tidyselect::all_of(c(match_var_nm_1L_chr,
.y))) %>% make_imputed_distinct_cases(uid_1L_chr = match_var_nm_1L_chr,
method_1L_chr = method_1L_chr)
complete_tb <- .x %>% dplyr::filter(!is.na(!!rlang::sym(.y)))
missing_tb <- .x %>% dplyr::filter(is.na(!!rlang::sym(.y)))
if (is.null(lup_prototype_tb)) {
distinct_tb <- .x %>% dplyr::select(tidyselect::all_of(c(match_var_nm_1L_chr,
.y))) %>% make_imputed_distinct_cases(uid_1L_chr = match_var_nm_1L_chr,
method_1L_chr = method_1L_chr)
}
else {
distinct_tb <- lup_prototype_tb %>% dplyr::select(tidyselect::all_of(c(match_var_nm_1L_chr,
.y)))
}
imputed_tb <- missing_tb %>% dplyr::select(-tidyselect::all_of(.y)) %>%
dplyr::left_join(distinct_tb %>% dplyr::select(tidyselect::all_of(c(match_var_nm_1L_chr,
.y))))
Expand Down
16 changes: 11 additions & 5 deletions data-raw/fns/add.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,28 @@ add_from_lup_prototype <- function (data_tb, arrange_1L_chr = character(0), excl
method_1L_chr = method_1L_chr)
data_tb <- data_tb %>% dplyr::left_join(distinct_tb)
}
if (type_1L_chr == "self") {
if (type_1L_chr %in% c("self", "impute")) {
if (identical(vars_chr, character(0))) {
vars_chr <- setdiff(names(data_tb), c(match_var_nm_1L_chr,
exclude_chr))
}
# excuded_tb <-
data_tb <- purrr::reduce(vars_chr, .init = data_tb, ~{
distinct_tb <- .x %>% dplyr::select(tidyselect::all_of(c(match_var_nm_1L_chr,
.y))) %>%
make_imputed_distinct_cases(uid_1L_chr = match_var_nm_1L_chr,
method_1L_chr = method_1L_chr)
complete_tb <- .x %>% dplyr::filter(!is.na(!!rlang::sym(.y)))
missing_tb <- .x %>% dplyr::filter(is.na(!!rlang::sym(.y)))
if(is.null(lup_prototype_tb)){
distinct_tb <- .x %>% dplyr::select(tidyselect::all_of(c(match_var_nm_1L_chr,
.y))) %>%
make_imputed_distinct_cases(uid_1L_chr = match_var_nm_1L_chr,
method_1L_chr = method_1L_chr)
}else{
distinct_tb <- lup_prototype_tb %>%
dplyr::select(tidyselect::all_of(c(match_var_nm_1L_chr, .y)))
}
imputed_tb <- missing_tb %>% dplyr::select(-tidyselect::all_of(.y)) %>%
dplyr::left_join(distinct_tb %>% dplyr::select(tidyselect::all_of(c(match_var_nm_1L_chr,
.y))))

dplyr::bind_rows(complete_tb, imputed_tb)
})
}
Expand Down

0 comments on commit 987ea62

Please sign in to comment.