Skip to content

Commit 4bd3abd

Browse files
committed
error with abc rendering. updated to gettin_started_with_ti
1 parent aa42521 commit 4bd3abd

20 files changed

+3512
-47
lines changed

554.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ x <- contoso::sales |> fpaR::mtd(order_date,margin,calendar_type = "445")
99

1010

1111

12-
1312
## find beginng date indicator
1413

1514

R/abc.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abc <- function(.data,category_values,.value){
4242

4343

4444
x <- segment_abc(
45-
datum = datum(.data,date_vec = NA,calendar_type = NA)
45+
datum = datum(.data,date_vec = NA,calendar_type = NA_character_)
4646
,value = value(value_vec = value_vec,new_column_name_vec = "abc")
4747
,category = category(category_values=category_values)
4848
,fn = fn(

R/classes.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ datum <- S7::new_class(
101101
,default = "standard"
102102
,validator =function(value){
103103

104-
valid_names <- c("standard","544","445","454")
104+
valid_names <- c("standard","544","445","454",NA_character_)
105105

106106
if(!any(value %in% valid_names)) return(cli::format_error("Please return {.or {.val {valid_names}}}"))
107107

_pkgdown.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
- title: "Utilities"
1616
desc: "General helper and execution utilities."
1717
contents:
18-
- augment_calendar
18+
- augment_standard_calendar
19+
- augment_non_standard_calendar
1920
- calculate
2021

2122
- title: "Cohort & Classification"

vignettes/articles/abc.qmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ subtitle: "How to use classification strategies to focus your analysis"
66

77
```{r}
88
#| echo: false
9+
10+
library(fpaR)
11+
912
quarto::write_yaml_metadata_block(
1013
date=format(Sys.Date())
1114
)

vignettes/articles/calendar_types.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Standard vs. 5-5-4 Calendar"
2+
title: "Standard vs. 5-4-4 Calendar"
33
subtitle: "What do we mean by standard and non-standard calendar?"
44
author: "Alejandro Hagan"
55
format: html

vignettes/articles/getting_started_with_ti.qmd

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,31 @@ format: html
1313
library(dplyr)
1414
library(fpaR)
1515
16-
1716
hook <- fansi::set_knit_hooks(knitr::knit_hooks, which = c("output", "warning", "error", "message"))
1817
1918
options(crayon.enabled = TRUE)
2019
20+
2121
```
2222

2323

2424
## How to use fpaR?
2525

26-
### Time Intelligence
27-
28-
When you execute a time intelligence function, it will return a "ti" class object with a custom print method that explains what the function is doing and a summary of transformation steps and the calendar attributes.
29-
3026
Simply pass your data in either tibble or a lazy DBI object to the time intelligence function and input the required arguments.
3127

3228
> Regardless if you pass a tibble or lazy DBI object, all time intelligence functions will return a lazy DBI object for performance reasons
3329
34-
We will use `mtd()` function to calculate the month-to-date sum of contoso's company' revenue (`contoso::sales`).
30+
We will use `mtd()` function to calculate the month-to-date sum of contoso's company' margin (`contoso::sales`).
3531

3632
Most time intelligence functions follow the same structure:
3733

38-
- specify the date column to index the time intelligence functions
39-
- specify the value column to aggregate
40-
- if there is a period rollback / rollforward then clarify the number of periods
41-
- clarify if we are using a "standard" calendar or non-standard variation (currently supports 5-5-4)
34+
- Specify the date column to index the time intelligence functions (eg. `order_date` or `deliver_date`)
35+
- Specify the value column to aggregate
36+
- If there is a period rollback / rollforward then clarify the number of periods to roll
37+
- Clarify if we are using a "standard" calendar or non-standard variation (currently supports 5-4-4, 4-4-5 and 4-5-4 calendars) see [standard vs. non standard calendar article](https://usrbinr.github.io/fpaR/articles/calendar_types.html)
38+
39+
> For most of your uses cases, you are likely to reference "standard" calendar which is your standard gregorian calendar:
40+
> - 365 days in a year except for leap years where you have 366, 7 days make up a week, January has 30 days, etc
4241
4342
When you execute `mtd()`, your console return a `ti` object and will print a summary of the function's actions, details the calendar's attributes, describes the main transformation steps and lists out possible next actions.
4443

@@ -49,7 +48,7 @@ When you execute `mtd()`, your console return a `ti` object and will print a su
4948
#| eval: true
5049
5150
contoso::sales |>
52-
fpaR::mtd(.date=order_date,.value = revenue,calendar_type = "standard")
51+
fpaR::mtd(.date=order_date,.value = margin,calendar_type = "standard")
5352
5453
```
5554

@@ -59,27 +58,23 @@ To return the results to a lazy tibble of results, pass the ti object through to
5958

6059
```{r}
6160
#| label: calculate-example
61+
#| eval: false
6262
#| echo: true
6363
#| warning: false
6464
#| error: false
6565
#| message: false
66-
#| eval: false
6766
6867
contoso::sales |>
6968
fpaR::mtd(.date=order_date,.value = margin,calendar_type = "standard") |>
7069
fpaR::calculate()
7170
```
7271

7372

74-
If you using a tibble, under the hood, `fpaR` is converting your data to
75-
a [duckdb](https://github.com/duckdb/duckdb-r) database.
76-
77-
If your data is in a database, the package will leverage
78-
[dbplyr](https://dbplyr.tidyverse.org/) to execute all the calculations.
73+
If you using a tibble, under the hood, `fpaR` is converting your data to a [duckdb](https://github.com/duckdb/duckdb-r) database
7974

80-
Either case use `dplyr::collect()` to return your results to a local
81-
tibble.
75+
If your data is in a database, the package will leverage [dbplyr](https://dbplyr.tidyverse.org/) to execute all the calculations
8276

77+
Either case use `dplyr::collect()` to return your results to a local tibble
8378

8479
```{r}
8580
#| label: collect-example
@@ -90,7 +85,8 @@ tibble.
9085
contoso::sales |>
9186
fpaR::mtd(.date=order_date,.value = margin,calendar_type = "standard") |>
9287
fpaR::calculate() |>
93-
dplyr::collect() |>
88+
dplyr::collect() |>
89+
dplyr::arrange(date) |>
9490
head(10)
9591
```
9692

@@ -112,22 +108,20 @@ contoso::sales |>
112108
113109
```
114110

115-
The functions will work with your database even if you don't have write permission by creatively leveraging CTEs to create interim tables.
111+
In the print, we
116112

117-
## Why do we need this package when we have lubridate?
113+
### Why do we need this package when we have lubridate?
118114

119-
[Lubridate](https://lubridate.tidyverse.org/) is an excellent package and is heavily used by the package. The issue isn't lubridate but rather
120-
issues you may not be aware of in your package.
115+
[Lubridate](https://lubridate.tidyverse.org/) is an excellent package and is heavily used by the package. The issue isn't lubridate but rather challenges and issues in your dataset that aren't readily visible.
121116

122-
Time-based comparisons, such as Year-over-Year (YoY), Quarter-over-Quarter (QoQ), and Month-to-Date (MTD), are common for tracking business performance. However, they come with challenges:
123117

124118
- Many datasets **do not have continuous dates**, especially if data is recorded only on business days or for active transactions
125119

126-
- Period imbalances between periods (Eg. the different number of days between February vs. January) can create misleading analysis or trends
127120

128-
- Your analysis may need to reference a non-standard calendar such as a 5-5-4, 4-4-5, or 13 month calendar
121+
- Period imbalances between periods (Eg. the different number of days between February vs. January) can create misleading analysis or trends requiring non-standard calendars (eg. 4-4-5)
122+
123+
- Calculating time intelligence for groups can lead to larger than memory issues even with smaller datasets
129124

130-
- Your data may be in excel sheets, csv or databases and you need to inter-operable framework to switch between all your data types
131125

132126
### Issue 1: Continuous Dates
133127

@@ -171,15 +165,17 @@ tibble::tibble(
171165

172166
## Issue 2: Period imbalances
173167

174-
When comparing two performance periods with a standard calendar, you often will compare a period with unequal number of days or periods. For example if you want to compare January sales to February you can get misleading conclusions due to the unequal number of weekends and days in those periods.
168+
When comparing two performance periods with a standard calendar, you often will compare a period with unequal number of days or periods.
169+
170+
For example if you want to compare January sales to February you can get misleading conclusions due to the unequal number of weekends and days in those periods.
175171

176172
> In practice you have two choices:
177173
>
178174
- compare periods with similar days (eg. the 28th of February compares should only compare up to the 28th of January) and you omit three days of January sales all together
179175
>
180176
- compare have an imbalanced comparison (eg. the 28th of February compares to the 31st of January so that no days are lost).
181177

182-
this package does the second option which is ensure we don't loose any of January's sales but to help flag for imbalance, fpaR will add a column to let you know how many periods (eg. days) are in your comparison period to increase transparency to this dynamic.
178+
This package does the second option to ensure we don't loose any of January's sales but to help flag for imbalance, fpaR will add a column to let you know how many periods (eg. days) are in your comparison period to increase transparency to this dynamic.
183179

184180
To create this example, we will use the `pmtd()` function to calculate the prior month to date cumulative margin in the current month.
185181

@@ -218,22 +214,15 @@ contoso::sales |>
218214
tinytable::tt(width=1)
219215
```
220216

221-
## what is going on under the hood
217+
### Issues 3: larger than memory
222218

223-
In financial planning and analysis, it is common to compare **year-to-date (YTD)** metrics against the **previous year's YTD** to understand performance trends.
219+
If your data isn't already in a database then fpaR will leverage duckdb to convert your data to enable larger than memory calculation.
224220

225-
The function `yoytd_fn()` provides this functionality. While it is an **internal, non-exported function**, it is called by [yoytd()] and executed through [calculate()].
221+
This is necessary for time intelligence functions because when you have grouped data, you need to complete calendar for each group combination. For even modest datasets, this can quickly multiple and grow you data to be larger than memory.
226222

227-
This vignette explains what the function does, how it works, and how to work with its output.
223+
If your data is already in database, then fpaR will use [dbplyr](https://dbplyr.tidyverse.org/) and will convert the functions to SQL to write the queries.
228224

229-
# Function Purpose
225+
In either scenario, you can use `dplyr::collect()` to execute your SQL query and return a tibble to your local computer.
230226

231-
`yoytd_fn()` performs the following:
232227

233-
1. Computes **current year-to-date (YTD)** values.
234-
2. Computes **previous year-to-date (PYTD)** values, optionally applying a lag.
235-
3. Joins YTD and PYTD tables together on `date`, `year`, and grouping variables.
236-
4. Fills missing dates downward for consistency.
237-
5. Summarizes the data by summing the YTD and PYTD values by group.
238228

239-
The output is a **DBI object** that can be converted into a **tibble** using `dplyr::collect()` for further analysis.

vignettes/articles/getting_started_with_ti_files/libs/bootstrap/bootstrap-c45587a26a1df833d5e643ccce865553.min.css

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)