Skip to content

Commit

Permalink
S7 objects introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrohagan committed Nov 23, 2024
1 parent 88e1587 commit b4ccb2b
Show file tree
Hide file tree
Showing 21 changed files with 636 additions and 299 deletions.
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ export(clean_file_names)
export(convert_dots_to_string)
export(convert_input_to_string)
export(count_plus)
export(cp)
export(create_contonso_duckdb)
export(cte)
export(d)
export(divide)
export(dod)
export(dod_dbi)
export(factor)
export(is_yyyy_mm_dd)
export(make_aggregation_dbi)
export(make_aggregation_tbl)
export(make_cohort_tbl)
export(make_segmentation)
export(mom)
export(mom_dbi)
export(pp)
export(seq_date_sql)
export(show_in_excel)
export(sql_query_select)
Expand Down
15 changes: 15 additions & 0 deletions R/clean_file_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
#' clean_file_names()
clean_file_names <- function(file_path,...){


# Assert that the directory exists
assertthat::assert_that(
fs::dir_exists(dir_path),
msg = cli::format_error("Directory {dir_path} does not exist.")
)

# Assert that the directory contains files

assertthat::assert_that(
length(files) > 0,
msg = cli::format_error("No files found in directory {dir_path}.")
)


fp <- file_path

old_names <- list.files(fp,full.names = TRUE)
Expand Down
14 changes: 11 additions & 3 deletions R/divide.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@
#' @export
#'
#' @examples
#' divide(mtcars,new_col_name=div_col,numerator=mpg,denominator=0,alternative_result=10)
divide <- function(.data,new_col_name,numerator,denominator,alternative_result=NA_integer_){
#' data(mtcars)
#' mtcars |> divide(new_col_name=div_col,numerator=mpg,denominator=0,alternative_result=10)
divide <- function(.data,new_col_name,numerator_col,denominator_col,alternative_result=NA_integer_){


assertthat::assert_that(
is.numeric(alternative_result),
msg = cli::format_error(c(
"x" = "Alternative result must be numeric.",
"!" = "You provided a value of class {.cls {class(alternative_result)}}."
))
)

out <- .data |>
dplyr::mutate(
"{{new_col_name}}":=dplyr::if_else(base::is.na({{numerator}}/{{denominator}})|base::is.infinite({{numerator}}/{{denominator}}),alternative_result,{{numerator}}/{{denominator}})
"{{new_col_name}}":=dplyr::if_else(base::is.na({{numerator_col}}/{{denominator_col}})|base::is.infinite({{numerator_col}}/{{denominator_col}}),alternative_result,{{numerator_col}}/{{denominator_col}})
)

base::return(out)
Expand Down
Empty file removed R/rlang.R
Empty file.
48 changes: 0 additions & 48 deletions R/show_in_excel.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/time_intelligence.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ make_aggregation_dbi <- function(.data, ..., date_var, value_var, time_unit){



#

# calculate <- function(.data,...,date_var,value_var,time_unit){
#
# # Validate inputs
Expand Down
44 changes: 43 additions & 1 deletion R/utils-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
#' @examples
#' is_yyyy_mm_dd("2024-01-01")
is_yyyy_mm_dd <- function(x) {
grepl("^\\d{4}-\\d{2}-\\d{2}$", x)

out <- suppressWarnings(!is.na(lubridate::ymd(x)))

return(out)


}


Expand Down Expand Up @@ -64,3 +69,40 @@ convert_dots_to_string <- function(...){
return(group_var)

}



#' Converts tibble to csv file and opens up in excel
#'
#' @param .data tibble of data
#'
#' @return a temp csv file
#' @export
#'
#' @examples
#' mtcars |> show_in_excel()
show_in_excel <- function(.data){

# supporting arguments
rows <- base::dim(.data)[1]
cols <- base::dim(.data)[2]

# send message based on table row size

cli::cli_alert("data contains {rows} row(s) and {cols} column(s)")

# create temp file path to be used later
temp <- base::paste0(base::tempfile(),".csv")

# save the table as a csv file
utils::write.csv(.data,file = temp)

# open up the csv file
fs::file_show(path=temp)

# alert that successful
cli::cli_alert_success("success: temp file {temp}")

}


30 changes: 23 additions & 7 deletions README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ title: "README"
format: gfm
---

ti.tbl_class # method
make_aggregation_tbl # method



# Developer Notes

## 2024-08-10
Expand Down Expand Up @@ -93,14 +98,30 @@ format: gfm

- eg. (lag_quanitity*price)+(price*quantity_prop)
- then have collector function eg. pvm() or something else take the columns names that are produced
- Create the required columns based on the column logic eg lag_quanitty means mutate(lag_quantity=lag(quantity,1))
- Create the required columns based on the column logic eg lag_quantity means mutate(lag_quantity=lag(quantity,1))
- easier to capture controls and create the problems all at once
- now need to figure out to pass lists onto each other pp() to cp() should augment column names with each and then same from data object

- so either we transfrom the dataframe as we go along eg each factor step mutates as we go along creating the columns
- so either we transform the data frame as we go along eg each factor step mutates as we go along creating the columns
- or factor step just passes along a list of formula and formula names to transform
- I went down route B but realizing its easier with route A

2024-09-30

- learnt about structure and how to pass instructions to data model for execution later on
- then factor will read the instructions apply to the formula, create the required columns and then apply them to the model
- structure wont work because it goes away when you apply downstream functions
- but if I keep everything

2024-11-22

- need re do with S7-- plan out flow (4 hours)
- time intelligence (8 hours)
- factor ( 16 hours)
- mayble sql lm (8 hours)
-


## to do list

- finalize time intelligence functions
Expand Down Expand Up @@ -254,8 +275,3 @@ tibble::tribble(








Loading

0 comments on commit b4ccb2b

Please sign in to comment.