Skip to content

Commit 6ae4ba5

Browse files
committed
echo cut
1 parent fba3103 commit 6ae4ba5

File tree

4 files changed

+68
-31
lines changed

4 files changed

+68
-31
lines changed

R/formattedcut.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#' group_by(`Lower class`, `Upper class`, `Class interval`) %>%
3434
#' tally())
3535
formattedcut <- function(data, breaks, cut = FALSE) {
36+
cut <- cut
3637
options(scipen = 999, digits = 2)
3738
if (cut == FALSE) {
3839
tally <- as.data.frame(table(cut(data, breaks, include.lowest = FALSE)))

R/mdpi.R

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#' number of options in the `Factor` argument must be less than 41. The default
5252
#' is `NULL`. To produce the plots, any character string will overwrite the
5353
#' default.
54+
#' @param Echo Optional indicating whether the progress note is visible
55+
#' defaults to TRUE.
5456
#'
5557
#' @returns A list with the following components:
5658
#' \item{\code{MDPI_p}}{Publication-ready table of the factor and national
@@ -121,7 +123,9 @@ mdpi <- function(data, dm, Bar = 0.4,
121123
plots = NULL,
122124
id = c("Health", "Education", "Living standard"),
123125
id_add = "Social security",
124-
id_add1 = "Employment and Income") {
126+
id_add1 = "Employment and Income",
127+
Echo = TRUE) {
128+
125129
Bar <- Bar
126130
Factor <- Factor
127131
plots <- plots
@@ -131,25 +135,31 @@ mdpi <- function(data, dm, Bar = 0.4,
131135
id_addn <- id_addn
132136
ddm <- length(dm)
133137
k <- 1 / ddm
138+
Echo <- Echo
139+
134140
if (ddm < 3L) {
135141
stop("Number of dimensions must be an integer not less than 3")
136142
} else if (ddm > 9L) {
137143
stop("Number of dimensions must be an integer not greater than 9")
138144
} else {
139-
cat("Number of dimensions correct, proceeding...", "\n")
145+
cata <- "Number of dimensions correct, proceeding..."
146+
progaress(Echo, cata)
140147
}
141148
if (!is.null(id_addn)) {
142149
id0 <- c(id, id_add, id_add1, id_addn)
143-
cat("Additional dimension is evaluated...", "\n")
150+
cata <- "Additional dimension is evaluated..."
151+
progaress(Echo, cata)
144152
} else if (ddm == 5) {
145153
id0 <- c(id, id_add, id_add1)
146154
cat("Additional dimension is null...", "\n")
147155
} else if (ddm == 4) {
148156
id0 <- c(id, id_add)
149-
cat("Additional dimension is null...", "\n")
157+
cata <- "Additional dimension is null..."
158+
progaress(Echo, cata)
150159
} else {
151160
id0 <- id
152-
cat("Additional dimension is null...", "\n")
161+
cata <- "Additional dimension is null..."
162+
progaress(Echo, cata)
153163
}
154164
Analysis <- c("q", "Non Poor", "n", "Incidence of poverty",
155165
rep("Adjusted incidence of poverty", ddm + 1),
@@ -159,7 +169,8 @@ mdpi <- function(data, dm, Bar = 0.4,
159169
rep("Contribution", ddm + 1),
160170
rep("Average deprivation among the deprived", ddm + 1))
161171
Order <- seq(1, length(Analysis), by = 1)
162-
cat("Computation commences...", "\n")
172+
cata <- "Computation commences..."
173+
progaress(Echo, cata)
163174
if (ddm == 3) {
164175
d1 <- data %>%
165176
dplyr::select(tidyselect::all_of(dm$d1))
@@ -402,7 +413,8 @@ mdpi <- function(data, dm, Bar = 0.4,
402413
}
403414
names(score) <- names(Mean) <- names(SD) <- id0
404415
id1 <- c("Combined", id0)
405-
cat("The computation is progressing...1", "\n")
416+
cata <- "The computation is progressing...1"
417+
progaress(Echo, cata)
406418
score <- data.frame(dplyr::bind_cols(Combined = rowSums(score), score))
407419
Mean <- data.frame(dplyr::bind_cols(Combined = rowMeans(score), Mean))
408420
SD <- data.frame(dplyr::bind_cols(Combined = apply(score, 1, sd), SD))
@@ -422,34 +434,43 @@ mdpi <- function(data, dm, Bar = 0.4,
422434
q <- nrow(score[score$Poverty == "Deprived", ])
423435
nq <- nrow(score) - q
424436
n <- q + nq
425-
cat("The computation is progressing...2", "\n")
437+
cata <- "The computation is progressing...2"
438+
progaress(Echo, cata)
426439
id2 <- "National"
427440
kay2 <- kkkk(q, nq, n, kay, id1, id2, ddm, Order, Analysis)
428-
cat("The computation is progressing...3", "\n")
441+
cata <- "The computation is progressing...3"
442+
progaress(Echo, cata)
429443
id2 <- "Mean"
430444
KaY2m <- kkkk(q, nq, n, kay = kay_mean, id1, id2, ddm, Order, Analysis)
431-
cat("The computation is progressing...4", "\n")
445+
cata <- "The computation is progressing...4"
446+
progaress(Echo, cata)
432447
id2 <- "SD"
433448
kaY2s <- kkkk(q, nq, n, kay = kay_SD, id1, id2, ddm, Order, Analysis)
434-
cat("The computation is progressing...5", "\n")
449+
cata <- "The computation is progressing...5"
450+
progaress(Echo, cata)
435451
if (!is.null(Factor)) {
436452
modEls2m <- mmmm(data, Scores, score = Mean, Factor, ddm, Analysis,
437453
kay2 = KaY2m)
438-
cat("The computation is progressing...6", "\n")
454+
cata <- "The computation is progressing...6"
455+
progaress(Echo, cata)
439456
modEls2s <- mmmm(data, Scores, score = SD, Factor, ddm, Analysis,
440457
kay2 = kaY2s)
441-
cat("The computation is progressing...7", "\n")
458+
cata <- "The computation is progressing...7"
459+
progaress(Echo, cata)
442460
models2 <- mmmm(data, Scores, score, Factor, ddm, Analysis, kay2)
443461
if (!is.null(plots) & length(unique(Factor)) > 40) {
444462
cat("Palette have 40 colors, plots not possible...", "\n")
445463
} else if (!is.null(plots) & length(unique(Factor)) < 41) {
446464
kala <- kolo_mix("Renoir", 40, type = "continuous", direction = -1)
447465
plots <- plot_mdpi(models2, kala, ddm, factor = Factor)
448-
cat("Proceeding after plots produced...", "\n")
466+
cata <- "Proceeding after plots produced..."
467+
progaress(Echo, cata)
449468
} else {
450-
cat("Proceeding without plots...", "\n")
469+
cata <- "Proceeding without plots..."
470+
progaress(Echo, cata)
451471
}
452-
cat("The computation is progressing...8", "\n")
472+
cata <- "The computation is progressing...8"
473+
progaress(Echo, cata)
453474
model_l <- list(MDPI_p = modelsummary::datasummary_df(models2, fmt = 4),
454475
MDPI = models2,
455476
national = cbind(kay2[, -1], Mean = KaY2m[, 4],
@@ -459,16 +480,19 @@ mdpi <- function(data, dm, Bar = 0.4,
459480
`MDPI mean` = modEls2m,
460481
`MDPI SD` = modEls2s,
461482
plots = plots)
462-
cat("National and factor MDPI...", "\n")
483+
cata <- "National and factor MDPI..."
484+
progaress(Echo, cata)
463485
} else {
464486
model_l <- list(national = cbind(kay2[, -1], Mean = KaY2m[, 4],
465487
SD = kaY2s[, 4]),
466488
dimensions = dds,
467489
Score = Scores,
468490
plots = plots)
469-
cat("National MDPI only...", "\n")
491+
cata <- "National MDPI only..."
492+
progaress(Echo, cata)
470493
}
471-
cat("The computation completed...", "\n")
494+
cata <- "The computation completed..."
495+
progaress(Echo, cata)
472496
return(model_l)
473497
}
474498
kkkk <- function(q, nq, n, kay, id1, id2, ddm, Order, Analysis) {
@@ -547,7 +571,7 @@ kolapalette <- list(
547571
Renoir = list(c("#17154f", "#2f357c", "#6c5d9e", "#9d9cd5", "#b0799a",
548572
"#f6b3b0", "#e48171", "#bf3729", "#e69b00", "#f5bb50",
549573
"#ada43b", "#355828"), c(2, 5, 9, 12, 3, 8, 7, 10, 4, 1, 6,
550-
11), colorblind=FALSE))
574+
11), colorblind = FALSE))
551575

552576
kolo_mix <- function(palette_name, n, type = c("discrete", "continuous"),
553577
direction = c(1, -1), override_order = FALSE,
@@ -585,15 +609,16 @@ kolo_mix <- function(palette_name, n, type = c("discrete", "continuous"),
585609
stop("Number of requested colors greater than what discrete palette offer")
586610
}
587611

588-
continuous <- if(direction==1){grDevices::colorRampPalette(palette[[1]])(n)
612+
continuous <- if(direction == 1) {
613+
grDevices::colorRampPalette(palette[[1]])(n)
589614
}else{
590615
grDevices::colorRampPalette(rev(palette[[1]]))(n)}
591616

592-
discrete <- if(direction==1 & override_order==FALSE){
593-
palette[[1]][which(palette[[2]] %in% c(1:n)==TRUE)]
594-
}else if(direction==-1 & override_order==FALSE){
595-
rev(palette[[1]][which(palette[[2]] %in% c(1:n)==TRUE)])
596-
} else if(direction==1 & override_order==TRUE){
617+
discrete <- if(direction == 1 & override_order == FALSE){
618+
palette[[1]][which(palette[[2]] %in% c(1:n) == TRUE)]
619+
}else if(direction == -1 & override_order == FALSE){
620+
rev(palette[[1]][which(palette[[2]] %in% c(1:n) == TRUE)])
621+
} else if(direction == 1 & override_order == TRUE){
597622
palette[[1]][1:n]
598623
} else{
599624
rev(palette[[1]])[1:n]
@@ -603,7 +628,14 @@ kolo_mix <- function(palette_name, n, type = c("discrete", "continuous"),
603628
continuous = continuous,
604629
discrete = discrete
605630
)
606-
if(return_hex==T){print(out)}
631+
if(return_hex == T) {print(out)}
607632
structure(out, class = "palette", name = palette_name)
608633
}
609634

635+
progaress <- function(Echo, cata) {
636+
if (Echo == TRUE) {
637+
cat(cata, "\n")
638+
} else{
639+
cat("", "\n")
640+
}
641+
}

R/relative_likert.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@
8484
relative_likert <- function(data, Likert = NULL, Ranks = NULL, Option = "text",
8585
Echo = TRUE) {
8686

87-
Likert = Likert
88-
Ranks = Ranks
89-
Echo = Echo
87+
Likert <- Likert
88+
Ranks <- Ranks
89+
Echo <- Echo
9090

9191
if (is.null(Likert) & is.null(Ranks)) {
9292
stop("**Likert** and **Ranks** arguments cannot be **NULL** at the same time")

man/mdpi.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)