@@ -49,19 +49,19 @@
Loading
49 49
50 50
  ulm <-
51 51
    mapdata %>%
52 -
    magrittr::extract2("monetary") %>%
52 +
    extract2("monetary") %>%
53 53
    max() %>%
54 54
    ceiling(.)
55 55
56 56
  llm <-
57 57
    mapdata %>%
58 -
    magrittr::extract2("monetary") %>%
58 +
    extract2("monetary") %>%
59 59
    min() %>%
60 60
    floor(.)
61 61
62 62
  bins <-
63 63
    mapdata %>%
64 -
    magrittr::use_series(frequency_score) %>%
64 +
    use_series(frequency_score) %>%
65 65
    max()
66 66
67 67
  guide_breaks <-
@@ -69,13 +69,13 @@
Loading
69 69
    round()
70 70
71 71
  p <-
72 -
    ggplot2::ggplot(data = mapdata) +
73 -
    ggplot2::geom_tile(ggplot2::aes(x = frequency_score, y = recency_score, fill = monetary)) +
74 -
    ggplot2::scale_fill_gradientn(limits = c(llm, ulm),
72 +
    ggplot(data = mapdata) +
73 +
    geom_tile(aes(x = frequency_score, y = recency_score, fill = monetary)) +
74 +
    scale_fill_gradientn(limits = c(llm, ulm),
75 75
                         colours = RColorBrewer::brewer.pal(n = brewer_n, name = brewer_name),
76 76
                         name = legend_title) +
77 -
    ggplot2::ggtitle(plot_title) + ggplot2::xlab(xaxis_title) + ggplot2::ylab(yaxis_title) +
78 -
    ggplot2::theme(plot.title = ggplot2::element_text(hjust = plot_title_justify))
77 +
    ggtitle(plot_title) + xlab(xaxis_title) + ylab(yaxis_title) +
78 +
    theme(plot.title = element_text(hjust = plot_title_justify))
79 79
80 80
  if (print_plot) {
81 81
    print(p)
@@ -132,14 +132,14 @@
Loading
132 132
133 133
  p <-
134 134
    rfm_hist_data(rfm_table) %>%
135 -
    ggplot2::ggplot(ggplot2::aes(score)) +
136 -
    ggplot2::geom_histogram(bins = hist_bins, fill = hist_color) +
137 -
    ggplot2::ylab(yaxis_title) + ggplot2::ggtitle(plot_title) + ggplot2::xlab(xaxis_title) +
138 -
    ggplot2::facet_grid(. ~ rfm, scales = "free_x",
139 -
      labeller = ggplot2::labeller(
135 +
    ggplot(aes(score)) +
136 +
    geom_histogram(bins = hist_bins, fill = hist_color) +
137 +
    ylab(yaxis_title) + ggtitle(plot_title) + xlab(xaxis_title) +
138 +
    facet_grid(. ~ rfm, scales = "free_x",
139 +
      labeller = labeller(
140 140
        rfm = c(amount = hist_m_label, recency_days = hist_r_label,
141 141
                transaction_count = hist_f_label))) +
142 -
    ggplot2::theme(plot.title = ggplot2::element_text(hjust = plot_title_justify))
142 +
    theme(plot.title = element_text(hjust = plot_title_justify))
143 143
144 144
  if (print_plot) {
145 145
    print(p)
@@ -185,17 +185,17 @@
Loading
185 185
186 186
  p <-
187 187
    rfm_barchart_data(rfm_table) %>%
188 -
    ggplot2::ggplot() +
189 -
    ggplot2::geom_bar(ggplot2::aes(x = monetary_score), fill = bar_color) +
190 -
    ggplot2::facet_grid(recency_score ~ frequency_score) +
191 -
    ggplot2::scale_y_continuous(sec.axis = ggplot2::sec_axis(~ ., name = sec_yaxis_title)) +
192 -
    ggplot2::xlab(xaxis_title) + ggplot2::ylab(" ") + ggplot2::ggtitle(sec_xaxis_title) +
193 -
    ggplot2::theme(
194 -
      plot.title = ggplot2::element_text(
188 +
    ggplot() +
189 +
    geom_bar(aes(x = monetary_score), fill = bar_color) +
190 +
    facet_grid(recency_score ~ frequency_score) +
191 +
    scale_y_continuous(sec.axis = sec_axis(~ ., name = sec_yaxis_title)) +
192 +
    xlab(xaxis_title) + ylab(" ") + ggtitle(sec_xaxis_title) +
193 +
    theme(
194 +
      plot.title = element_text(
195 195
        face = "plain", size = 11, hjust = 0.5
196 196
      ),
197 -
      axis.text.y = ggplot2::element_blank(),
198 -
      axis.ticks.y = ggplot2::element_blank()
197 +
      axis.text.y = element_blank(),
198 +
      axis.ticks.y = element_blank()
199 199
    )
200 200
201 201
  if (print_plot) {
@@ -248,26 +248,26 @@
Loading
248 248
249 249
  data <-
250 250
    rfm_table %>%
251 -
    magrittr::use_series(rfm) %>%
251 +
    use_series(rfm) %>%
252 252
    dplyr::count(transaction_count)
253 253
254 254
  ylim_max <-
255 255
    data %>%
256 256
    dplyr::pull(n) %>%
257 257
    max() %>%
258 -
    magrittr::multiply_by(1.1) %>%
258 +
    multiply_by(1.1) %>%
259 259
    ceiling(.)
260 260
261 261
  p <-
262 262
    data %>%
263 -
    ggplot2::ggplot(ggplot2::aes(x = transaction_count, y = n)) +
264 -
    ggplot2::geom_bar(stat = "identity", fill = bar_color) +
265 -
    ggplot2::xlab(xaxis_title) + ggplot2::ylab(yaxis_title) + ggplot2::ylim(0, ylim_max) +
266 -
    ggplot2::ggtitle(plot_title) +
267 -
    ggplot2::geom_text(
268 -
      ggplot2::aes(label = n, y = n + 3), position = ggplot2::position_dodge(0.9), vjust = 0
263 +
    ggplot(aes(x = transaction_count, y = n)) +
264 +
    geom_bar(stat = "identity", fill = bar_color) +
265 +
    xlab(xaxis_title) + ylab(yaxis_title) + ylim(0, ylim_max) +
266 +
    ggtitle(plot_title) +
267 +
    geom_text(
268 +
      aes(label = n, y = n + 3), position = position_dodge(0.9), vjust = 0
269 269
    ) +
270 -
    ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5))
270 +
    theme(plot.title = element_text(hjust = 0.5))
271 271
272 272
  if (print_plot) {
273 273
    print(p)
@@ -316,10 +316,10 @@
Loading
316 316
317 317
  p <-
318 318
    rfm_table %>%
319 -
    magrittr::use_series(rfm) %>%
320 -
    ggplot2::ggplot() +
321 -
    ggplot2::geom_point(ggplot2::aes(x = amount, y = recency_days), color = point_color) +
322 -
    ggplot2::xlab(xaxis_title) + ggplot2::ylab(yaxis_title) + ggplot2::ggtitle(plot_title)
319 +
    use_series(rfm) %>%
320 +
    ggplot() +
321 +
    geom_point(aes(x = amount, y = recency_days), color = point_color) +
322 +
    xlab(xaxis_title) + ylab(yaxis_title) + ggtitle(plot_title)
323 323
324 324
  if (print_plot) {
325 325
    print(p)
@@ -339,10 +339,10 @@
Loading
339 339
340 340
  p <-
341 341
    rfm_table %>%
342 -
    magrittr::use_series(rfm) %>%
343 -
    ggplot2::ggplot() +
344 -
    ggplot2::geom_point(ggplot2::aes(x = amount, y = transaction_count), color = point_color) +
345 -
    ggplot2::xlab(xaxis_title) + ggplot2::ylab(yaxis_title) + ggplot2::ggtitle(plot_title)
342 +
    use_series(rfm) %>%
343 +
    ggplot() +
344 +
    geom_point(aes(x = amount, y = transaction_count), color = point_color) +
345 +
    xlab(xaxis_title) + ylab(yaxis_title) + ggtitle(plot_title)
346 346
347 347
  if (print_plot) {
348 348
    print(p)
@@ -362,10 +362,10 @@
Loading
362 362
363 363
  p <-
364 364
    rfm_table %>%
365 -
    magrittr::use_series(rfm) %>%
366 -
    ggplot2::ggplot() +
367 -
    ggplot2::geom_point(ggplot2::aes(x = transaction_count, y = recency_days), color = point_color) +
368 -
    ggplot2::xlab(xaxis_title) + ggplot2::ylab(yaxis_title) + ggplot2::ggtitle(plot_title)
365 +
    use_series(rfm) %>%
366 +
    ggplot() +
367 +
    geom_point(aes(x = transaction_count, y = recency_days), color = point_color) +
368 +
    xlab(xaxis_title) + ylab(yaxis_title) + ggtitle(plot_title)
369 369
370 370
  if (print_plot) {
371 371
    print(p)

@@ -60,7 +60,7 @@
Loading
60 60
      recency_days = (analysis_date - !! recent_visit) / lubridate::ddays()
61 61
    ) %>%
62 62
    dplyr::select(!! cust_id, recency_days, !! order_count, !! revenues) %>%
63 -
    magrittr::set_names(c("customer_id", "recency_days", "transaction_count", "amount"))
63 +
    set_names(c("customer_id", "recency_days", "transaction_count", "amount"))
64 64
65 65
  result$recency_score   <- NA
66 66
  result$frequency_score <- NA

@@ -8,7 +8,7 @@
Loading
8 8
#'
9 9
rfm_launch_app <- function() {
10 10
11 -
	rlang::inform("`rfm_launch_app()` has been soft-deprecated and will be removed in the next release. In future, to launch the app, run the below code:\n 
11 +
	message("`rfm_launch_app()` has been soft-deprecated and will be removed in the next release. In future, to launch the app, run the below code:\n 
12 12
	- install.packages('xplorerr')\n - xplorerr::app_rfm_analysis()\n")
13 13
14 14
	check_suggests('haven')

@@ -1,4 +1,3 @@
Loading
1 -
#' @importFrom utils packageVersion
2 1
.onAttach <- function(...) {
3 2
4 3
  if (!interactive() || stats::runif(1) > 0.1) return()

@@ -65,7 +65,7 @@
Loading
65 65
      !! cust_id, date_most_recent, recency_days, transaction_count,
66 66
      amount
67 67
    ) %>%
68 -
    magrittr::set_names(c("customer_id", "date_most_recent", "recency_days", "transaction_count", "amount"))
68 +
    set_names(c("customer_id", "date_most_recent", "recency_days", "transaction_count", "amount"))
69 69
70 70
  result$recency_score   <- NA
71 71
  result$frequency_score <- NA

@@ -1,24 +1,27 @@
Loading
1 -
#' @importFrom magrittr %>% %<>%
1 +
#' @import magrittr 
2 +
#' @import ggplot2
3 +
#' @import dplyr
4 +
#' @import stats
2 5
bins <- function(data, value, n_bins) {
3 6
4 -
  my_value   <- rlang::enquo(value)
7 +
  my_value   <- enquo(value)
5 8
  length_out <- n_bins + 1
6 9
7 10
  data %>%
8 -
    dplyr::pull(!! my_value) %>%
9 -
    stats::quantile(probs = seq(0, 1, length.out = length_out)) %>%
11 +
    pull(!! my_value) %>%
12 +
    quantile(probs = seq(0, 1, length.out = length_out)) %>%
10 13
    unname() %>%
11 -
    magrittr::extract(c(-1, -length_out)) %>%
12 -
    magrittr::add(1)
14 +
    extract(c(-1, -length_out)) %>%
15 +
    add(1)
13 16
14 17
}
15 18
16 19
bins_lower <- function(data, value, bins) {
17 20
18 -
  my_value <- rlang::enquo(value)
21 +
  my_value <- enquo(value)
19 22
20 23
  data %>%
21 -
    dplyr::pull(!! my_value) %>%
24 +
    pull(!! my_value) %>%
22 25
    min() %>%
23 26
    append(bins)
24 27
@@ -26,13 +29,13 @@
Loading
26 29
27 30
bins_upper <- function(data, value, bins) {
28 31
29 -
  my_value <- rlang::enquo(value)
32 +
  my_value <- enquo(value)
30 33
31 34
  data_max <-
32 35
    data %>%
33 -
    dplyr::pull(!! my_value) %>%
36 +
    pull(!! my_value) %>%
34 37
    max() %>%
35 -
    magrittr::add(1)
38 +
    add(1)
36 39
37 40
  c(bins, data_max)
38 41
}
@@ -40,10 +43,10 @@
Loading
40 43
41 44
check_levels <- function(rfm_heatmap_data, column) {
42 45
43 -
  my_column <- rlang::enquo(column)
46 +
  my_column <- enquo(column)
44 47
45 48
  rfm_heatmap_data %>%
46 -
    dplyr::pull(!! my_column) %>%
49 +
    pull(!! my_column) %>%
47 50
    as.factor() %>%
48 51
    levels() %>%
49 52
    as.vector() %>%
@@ -58,14 +61,14 @@
Loading
58 61
  extra_data        <- expand.grid(missing2, seq_len(n_bins), 0)
59 62
  names(extra_data) <- names(rfm_heatmap_data)
60 63
61 -
  dplyr::bind_rows(rfm_heatmap_data, extra_data)
64 +
  bind_rows(rfm_heatmap_data, extra_data)
62 65
63 66
}
64 67
65 -
#' @importFrom utils packageVersion menu install.packages
68 +
#' @import utils
66 69
check_suggests <- function(pkg) {
67 70
68 -
  pkg_flag <- tryCatch(utils::packageVersion(pkg), error = function(e) NA)
71 +
  pkg_flag <- tryCatch(packageVersion(pkg), error = function(e) NA)
69 72
70 73
  if (is.na(pkg_flag)) {
71 74
@@ -73,8 +76,8 @@
Loading
73 76
74 77
    if (interactive()) {
75 78
      message(msg, "\nWould you like to install it?")
76 -
      if (utils::menu(c("Yes", "No")) == 1) {
77 -
        utils::install.packages(pkg)
79 +
      if (menu(c("Yes", "No")) == 1) {
80 +
        install.packages(pkg)
78 81
      } else {
79 82
        stop(msg, call. = FALSE)
80 83
      }

@@ -57,7 +57,7 @@
Loading
57 57
  result <-
58 58
    data %>%
59 59
    dplyr::select(!! cust_id, !! n_recency, !! order_count, !! revenues) %>%
60 -
    magrittr::set_names(c("customer_id", "recency_days", "transaction_count", "amount"))
60 +
    set_names(c("customer_id", "recency_days", "transaction_count", "amount"))
61 61
62 62
  result$recency_score   <- NA
63 63
  result$frequency_score <- NA

@@ -42,7 +42,7 @@
Loading
42 42
43 43
  rfm_score_table <-
44 44
    data %>%
45 -
    magrittr::use_series(rfm) %>%
45 +
    use_series(rfm) %>%
46 46
    dplyr::mutate(segment = 1)
47 47
48 48
  n_segments <- length(segment_names)
@@ -109,19 +109,18 @@
Loading
109 109
    dplyr::group_by(segment) %>%
110 110
    dplyr::select(segment, recency_days) %>%
111 111
    dplyr::summarise(avg_recency = stats::median(recency_days)) %>%
112 -
    # dplyr::rename(segment = segment, avg_recency = `median(recency_days)`) %>%
113 112
    dplyr::arrange(avg_recency)
114 113
115 114
  n_fill <- nrow(data)
116 115
117 116
  p <-
118 -
    ggplot2::ggplot(data, ggplot2::aes(segment, avg_recency)) +
119 -
    ggplot2::geom_bar(stat = "identity", fill = ggthemes::calc_pal()(n_fill)) +
120 -
    ggplot2::xlab("Segment") + ggplot2::ylab("Median Recency") +
121 -
    ggplot2::ggtitle("Median Recency by Segment") +
122 -
    ggplot2::coord_flip() +
123 -
    ggplot2::theme(
124 -
      plot.title = ggplot2::element_text(hjust = 0.5)
117 +
    ggplot(data, aes(segment, avg_recency)) +
118 +
    geom_bar(stat = "identity", fill = ggthemes::calc_pal()(n_fill)) +
119 +
    xlab("Segment") + ylab("Median Recency") +
120 +
    ggtitle("Median Recency by Segment") +
121 +
    coord_flip() +
122 +
    theme(
123 +
      plot.title = element_text(hjust = 0.5)
125 124
    )
126 125
127 126
  if (print_plot) {
@@ -151,13 +150,13 @@
Loading
151 150
  n_fill <- nrow(data)
152 151
153 152
  p <-
154 -
    ggplot2::ggplot(data, ggplot2::aes(segment, avg_frequency)) +
155 -
    ggplot2::geom_bar(stat = "identity", fill = ggthemes::calc_pal()(n_fill)) +
156 -
    ggplot2::xlab("Segment") + ggplot2::ylab("Median Frequency") +
157 -
    ggplot2::ggtitle("Median Frequency by Segment") +
158 -
    ggplot2::coord_flip() +
159 -
    ggplot2::theme(
160 -
      plot.title = ggplot2::element_text(hjust = 0.5)
153 +
    ggplot(data, aes(segment, avg_frequency)) +
154 +
    geom_bar(stat = "identity", fill = ggthemes::calc_pal()(n_fill)) +
155 +
    xlab("Segment") + ylab("Median Frequency") +
156 +
    ggtitle("Median Frequency by Segment") +
157 +
    coord_flip() +
158 +
    theme(
159 +
      plot.title = element_text(hjust = 0.5)
161 160
    )
162 161
163 162
  if (print_plot) {
@@ -188,13 +187,13 @@
Loading
188 187
  n_fill <- nrow(data)
189 188
190 189
  p <-
191 -
    ggplot2::ggplot(data, ggplot2::aes(segment, avg_monetary)) +
192 -
    ggplot2::geom_bar(stat = "identity", fill = ggthemes::calc_pal()(n_fill)) +
193 -
    ggplot2::xlab("Segment") + ggplot2::ylab("Median Monetary Value") +
194 -
    ggplot2::ggtitle("Median Monetary Value by Segment") +
195 -
    ggplot2::coord_flip() +
196 -
    ggplot2::theme(
197 -
      plot.title = ggplot2::element_text(hjust = 0.5)
190 +
    ggplot(data, aes(segment, avg_monetary)) +
191 +
    geom_bar(stat = "identity", fill = ggthemes::calc_pal()(n_fill)) +
192 +
    xlab("Segment") + ylab("Median Monetary Value") +
193 +
    ggtitle("Median Monetary Value by Segment") +
194 +
    coord_flip() +
195 +
    theme(
196 +
      plot.title = element_text(hjust = 0.5)
198 197
    )
199 198
200 199
  if (print_plot) {
Files Coverage
R 88.69%
Project Totals (9 files) 88.69%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
        informational: true
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
14
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading