Skip to content

Commit 737fec1

Browse files
committed
fix: resolved errors in the new get-rm-stats and tidy-env
1 parent fd015b5 commit 737fec1

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

R/get-rm-stats.R

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' @param id_var name of id variable in df
1010
#' @param age_var name of age variable in df
1111
#' @param conns connection object for DataSHIELD backends
12-
#'
12+
#'
1313
#' @return a tibble containing the following columns:
1414
#'
1515
#' min_age: 5th percentile of age
@@ -23,7 +23,7 @@
2323
#' @export
2424
dh.getRmStats <- function(df = NULL, outcome = NULL, id_var = NULL, age_var = NULL, conns = NULL) {
2525
variable <- perc_5 <- perc_95 <- cohort <- min_age <- max_age <- valid_n <- NULL
26-
26+
2727
if (is.null(df)) {
2828
stop("Please provide the name of a datashield dataframe")
2929
}
@@ -47,7 +47,7 @@ dh.getRmStats <- function(df = NULL, outcome = NULL, id_var = NULL, age_var = NU
4747
## ---- First get overall stats for some of the easy ones -------------------------------------------
4848
stats <- dh.getStats(
4949
df = df,
50-
vars = c(outcome, age_var),
50+
vars = c(outcome, age_var),
5151
conns = conns
5252
)
5353

@@ -77,7 +77,7 @@ dh.getRmStats <- function(df = NULL, outcome = NULL, id_var = NULL, age_var = NU
7777
X.name = "data$weight",
7878
INDEX.names = "id_fact",
7979
FUN.name = "N",
80-
newobj = "id_summary",
80+
newobj = "id_summary",
8181
datasources = conns
8282
)
8383

@@ -87,49 +87,49 @@ dh.getRmStats <- function(df = NULL, outcome = NULL, id_var = NULL, age_var = NU
8787
mutate(combined = rowSums(.)) %>%
8888
pivot_longer(
8989
cols = everything(),
90-
names_to = "cohort",
90+
names_to = "cohort",
9191
values_to = "n_participants"
9292
)
93-
94-
## ---- Median number of weight measurements per child ----------------------------------------
9593

96-
# We can use the ds.quantileMean function with the object we created above to get the
94+
## ---- Median number of weight measurements per child ----------------------------------------
95+
96+
# We can use the ds.quantileMean function with the object we created above to get the
9797
# median number of measurements per child.
9898

9999
ds.asNumeric("id_summary$N", "id_summary_num", datasources = conns)
100100

101-
quants <- DSI::datashield.aggregate(conns, as.symbol("quantileMeanDS(id_summary_num)"))
101+
quants <- DSI::datashield.aggregate(conns, as.symbol("quantileMeanDS(id_summary_num)"))
102102

103103
weight_med_iqr <- quants %>%
104-
bind_rows(.id = "cohort") %>%
105-
select(cohort, "5%", "50%", "95%") %>%
106-
rename(n_meas_med = "50%", n_meas_5 = "5%", n_meas_95 = "95%")
104+
bind_rows(.id = "cohort") %>%
105+
select(cohort, "5%", "50%", "95%") %>%
106+
rename(n_meas_med = "50%", n_meas_5 = "5%", n_meas_95 = "95%")
107107

108108
## Get the combined version using weighted sum
109-
lengths <- DSI::datashield.aggregate(conns, call('lengthDS', "id_summary_num"))
109+
lengths <- DSI::datashield.aggregate(conns, call("lengthDS", "id_summary_num"))
110110
numNAs <- DSI::datashield.aggregate(conns, "numNaDS(id_summary_num)")
111-
112-
valid_n <- list(lengths, numNAs) %>% pmap(~.x - .y)
113111

114-
weights <- unlist(valid_n) / sum(unlist(valid_n))
112+
valid_n <- list(lengths, numNAs) %>% pmap(~ .x - .y)
115113

116-
weighted_quant <- list(quants, weights) %>% pmap(~.x * .y)
114+
weights <- unlist(valid_n) / sum(unlist(valid_n))
117115

118-
sum_quant <- weighted_quant %>%
119-
pmap(function(...){
120-
sum(c(...))
121-
}) %>%
122-
bind_rows %>%
123-
rename(n_meas_med = "50%", n_meas_5 = "5%", n_meas_95 = "95%") %>%
124-
mutate(cohort = "combined") %>%
125-
select(cohort, n_meas_med, n_meas_5, n_meas_95)
116+
weighted_quant <- list(quants, weights) %>% pmap(~ .x * .y)
117+
118+
sum_quant <- weighted_quant %>%
119+
pmap(function(...) {
120+
sum(c(...))
121+
}) %>%
122+
bind_rows() %>%
123+
rename(n_meas_med = "50%", n_meas_5 = "5%", n_meas_95 = "95%") %>%
124+
mutate(cohort = "combined") %>%
125+
select(cohort, n_meas_med, n_meas_5, n_meas_95)
126126

127-
quant_out <- bind_rows(weight_med_iqr, sum_quant)
127+
quant_out <- bind_rows(weight_med_iqr, sum_quant)
128128

129-
## ---- Create final output -------------------------------------------------------------------
130-
out <- left_join(age_ranges, outcome_n, by = "cohort") %>%
131-
left_join(., n_subjects, by = "cohort") %>%
132-
left_join(., quant_out, by = "cohort")
129+
## ---- Create final output -------------------------------------------------------------------
130+
out <- left_join(age_ranges, outcome_n, by = "cohort") %>%
131+
left_join(., n_subjects, by = "cohort") %>%
132+
left_join(., quant_out, by = "cohort")
133133

134-
return(out)
134+
return(out)
135135
}

R/tidy-env.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#'
1818
#' @export
1919
dh.tidyEnv <- function(obj = NULL, type = c("remove", "keep"), conns = NULL) {
20-
. <- NULL
20+
. <- n_meas_5 <- n_meas_95 <- n_meas_med <- NULL
2121

2222
if (is.null(obj)) {
2323
stop("Please specify one or more objects to remove from environment")
@@ -62,7 +62,7 @@ dh.tidyEnv <- function(obj = NULL, type = c("remove", "keep"), conns = NULL) {
6262
bind_rows()
6363

6464
vars_tibble %>% pmap(function(cohort, value) {
65-
ds.rm(x.name = value, datasources = conns[cohort])
65+
ds.rm(x.names = value, datasources = conns[cohort])
6666
})
6767
}
6868
}

0 commit comments

Comments
 (0)