@@ -246,10 +246,12 @@
Loading
246 246
                           plot_title = 'Customers by Orders',
247 247
                           plot_title_justify = 0.5, print_plot = TRUE) {
248 248
249 -
250 -
  d <- data.table(rfm_table$rfm)
251 -
  data <- d[, .(n = .N), by = transaction_count]
252 -
  setDF(data)
249 +
  data <- 
250 +
    rfm_table %>% 
251 +
    use_series(rfm) %>% 
252 +
    data.table() %>% 
253 +
    .[, .(n = .N), by = transaction_count] %>% 
254 +
    setDF()
253 255
254 256
  ylim_max <-
255 257
    data %>%

@@ -54,12 +54,14 @@
Loading
54 54
  recent_visit <- deparse(substitute(latest_visit_date))
55 55
  reven        <- deparse(substitute(total_revenue))
56 56
57 -
  dm <- data.table(data)
58 -
  dm[, ':='(recency_days = as.numeric(analysis_date - get(recent_visit), units = "days"))]
59 -
  result <- dm[, .(get(cust_id), recency_days, get(order_count), get(reven))]
60 -
  setDF(result)
57 +
  result <- 
58 +
    data %>% 
59 +
    data.table() %>% 
60 +
    .[, ':='(recency_days = as.numeric(analysis_date - get(recent_visit), units = "days"))] %>% 
61 +
    .[, .(get(cust_id), recency_days, get(order_count), get(reven))] %>% 
62 +
    setDF()
63 +
  
61 64
  colnames(result) <- c("customer_id", "recency_days", "transaction_count", "amount")
62 -
63 65
  out <- rfm_prep_bins(result, recency_bins, frequency_bins, monetary_bins, analysis_date)
64 66
65 67
  class(out) <- c("rfm_table_customer_2", "tibble", "data.frame")

@@ -25,13 +25,14 @@
Loading
25 25
#'
26 26
rfm_heatmap_data <- function(rfm_table) {
27 27
28 -
  d <- data.table(rfm_table$rfm)
29 -
  d <- d[, .(frequency_score, recency_score, amount)]
30 -
  result <-
31 -
    d[,
32 -
      .(monetary = mean(amount)),
33 -
      keyby = .(frequency_score, recency_score)]
34 -
  setDF(result)
28 +
  result <- 
29 +
    rfm_table %>% 
30 +
    use_series(rfm) %>% 
31 +
    data.table() %>% 
32 +
    .[, .(frequency_score, recency_score, amount)] %>% 
33 +
    .[, .(monetary = mean(amount)), 
34 +
      keyby = .(frequency_score, recency_score)] %>% 
35 +
    setDF()
35 36
36 37
  l_frequency      <- check_levels(result, frequency_score)
37 38
  l_recency        <- check_levels(result, recency_score)

@@ -66,19 +66,17 @@
Loading
66 66
67 67
rfm_prep_table_data <- function(data, customer_id, order_date, revenue, analysis_date) {
68 68
69 -
  dm <- data.table(data)
70 -
  dm <- dm[, .(customer_id, order_date, revenue)]
71 -
  by_cust <- 
72 -
    dm[, .(date_most_recent = max(order_date),
73 -
         amount = sum(revenue),
74 -
         transaction_count = .N), 
75 -
     by = customer_id]
76 -
  
77 -
  by_cust[, ':='(recency_days = as.numeric(analysis_date - date_most_recent, units = "days"))]
78 -
  
79 -
  result <- by_cust[, .(customer_id, recency_days, transaction_count, amount)]
80 -
  setDF(result)
81 -
  colnames(result) <- c("customer_id", "recency_days", "transaction_count", "amount")
69 +
  result <- 
70 +
    data %>% 
71 +
    data.table() %>% 
72 +
    .[, .(date_most_recent = max(order_date),
73 +
          amount = sum(revenue),
74 +
          transaction_count = .N), 
75 +
      by = customer_id] %>% 
76 +
    .[, ':='(recency_days = as.numeric(analysis_date - date_most_recent, units = "days"))] %>% 
77 +
    .[, .(customer_id, recency_days, transaction_count, amount)] %>% 
78 +
    setDF()
79 +
82 80
  return(result)
83 81
}
84 82

@@ -54,9 +54,12 @@
Loading
54 54
  n_recency   <- deparse(substitute(recency_days))
55 55
  revenues    <- deparse(substitute(total_revenue))
56 56
57 -
  dm <- data.table(data)
58 -
  result <- dm[, .(get(cust_id), get(n_recency), get(order_count), get(revenues))]
59 -
  setDF(result)
57 +
  result <- 
58 +
    data %>% 
59 +
    data.table() %>% 
60 +
    .[, .(get(cust_id), get(n_recency), get(order_count), get(revenues))] %>% 
61 +
    setDF()
62 +
    
60 63
  colnames(result) <- c("customer_id", "recency_days", "transaction_count", "amount")
61 64
  out <- rfm_prep_bins(result, recency_bins, frequency_bins, monetary_bins, analysis_date)
62 65

@@ -42,9 +42,6 @@
Loading
42 42
43 43
  rfm_score_table <- data$rfm
44 44
  rfm_score_table$segment <- 1
45 -
    # data %>%
46 -
    # use_series(rfm) %>%
47 -
    # dplyr::mutate(segment = 1)
48 45
49 46
  n_segments <- length(segment_names)
50 47
@@ -97,16 +94,17 @@
Loading
97 94
#'
98 95
rfm_segment_summary <- function(segments) {
99 96
100 -
  dm <- data.table(segments)
101 -
  by_seg <-
102 -
  dm[, .(customers = .N,
97 +
  result <- 
98 +
    segments %>% 
99 +
    data.table() %>% 
100 +
    .[, .(customers = .N,
103 101
          orders = sum(transaction_count),
104 102
          revenue = sum(amount)),
105 -
      by = segment]
103 +
      by = segment] %>% 
104 +
    setDF()
106 105
107 -
  setDF(by_seg)
108 -
  by_seg$aov <- by_seg$revenue / by_seg$orders
109 -
  return(by_seg)
106 +
  result$aov <- result$revenue / result$orders
107 +
  return(result)
110 108
111 109
}
112 110
@@ -403,12 +401,15 @@
Loading
403 401
404 402
  met <- deparse(substitute(metric))
405 403
406 -
  d <- data.table(rfm_segment_table)
407 -
  dm   <- d[, .(segment, met = get(met))]
408 -
  result <- dm[, .(mem = median(met)), by = segment]
409 -
  setDF(result)
410 -
  result <- result[order(result$mem), ]
411 -
  colnames(result) <- c("segment", met)
404 +
  result <- 
405 +
    rfm_segment_table %>% 
406 +
    data.table() %>% 
407 +
    .[, .(segment, met = get(met))] %>% 
408 +
    .[, .(mem = median(met)), by = segment] %>% 
409 +
    .[order(mem)] %>% 
410 +
    setnames(old = "mem", new = met) %>%
411 +
    setDF()
412 +
412 413
  return(result)
413 414
414 415
}
Files Coverage
R 87.40%
Project Totals (9 files) 87.40%
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