From 9428d4adef850263326ebb205c86335c7de1c9e8 Mon Sep 17 00:00:00 2001 From: asenetcky Date: Wed, 23 Oct 2024 06:25:57 -0400 Subject: [PATCH 1/6] rename pipeline to stratum, pipelines to strata --- R/builders.R | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/R/builders.R b/R/builders.R index 3f6d1c8..65ef508 100644 --- a/R/builders.R +++ b/R/builders.R @@ -1,27 +1,27 @@ #' Add a pipeline skeleton to your project space #' -#' @param pipeline_name A string that is the name of your pipeline -#' @param path a path to where you want to drop your pipeline -#' @param order the order of the pipeline +#' @param stratum_name A string that is the name of your stratum +#' @param path a path to where you want to drop your stratum +#' @param order the order of the stratum #' -#' @return invisibly returns fs::path to pipeline +#' @return invisibly returns fs::path to stratum #' @export #' #' @examples -#' build_pipeline("my_pipeline_name", "PATH/TO/PROJECT/FOLDER/") -build_pipeline <- function(pipeline_name, path = ".", order = 1) { +#' build_stratum("my_stratum_name", "PATH/TO/PROJECT/FOLDER/") +build_stratum <- function(stratum_name, path = ".", order = 1) { #what if we dug into strata name more, pipeline becomes stratum? # module becomes lamina? flows? # Clean file name - pipeline_name <- clean_name(pipeline_name) + stratum_name <- clean_name(stratum_name) - # Create paths for project and pipeline + # Create paths for project and stratum project_folder <- fs::path(path) - pipelines_folder <- fs::path(project_folder, "pipelines") - target_pipeline <- fs::path(pipelines_folder, pipeline_name) - pipelines_toml <- fs::path(pipelines_folder, ".pipelines.toml") + strata_folder <- fs::path(project_folder, "strata") + target_stratum <- fs::path(strata_folder, stratum_name) + strata_toml <- fs::path(strata_folder, ".strata.toml") # Create folders fs::dir_create(target_pipeline, recurse = TRUE) From 80882c444fa6306a471c9534c00804a3aa84bc8c Mon Sep 17 00:00:00 2001 From: asenetcky Date: Thu, 24 Oct 2024 20:04:42 -0400 Subject: [PATCH 2/6] pipeline/s to strata/um --- NAMESPACE | 2 +- R/builders.R | 90 ++++++++++++++++++++----------------------- R/main.R | 20 +++++----- R/source_wrappers.R | 14 +++---- R/toml.R | 6 +-- R/utils.R | 16 ++++---- man/build_pipeline.Rd | 24 ------------ man/build_stratum.Rd | 24 ++++++++++++ man/strata-package.Rd | 2 +- 9 files changed, 95 insertions(+), 103 deletions(-) delete mode 100644 man/build_pipeline.Rd create mode 100644 man/build_stratum.Rd diff --git a/NAMESPACE b/NAMESPACE index 2aa4dd1..655f9a3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand -export(build_pipeline) +export(build_stratum) export(log_error) export(log_message) export(log_total_time) diff --git a/R/builders.R b/R/builders.R index 216c24f..c52122f 100644 --- a/R/builders.R +++ b/R/builders.R @@ -1,4 +1,4 @@ -#' Add a pipeline skeleton to your project space +#' Add a stratum skeleton to your project space #' #' @param stratum_name A string that is the name of your stratum #' @param path a path to where you want to drop your stratum @@ -10,10 +10,6 @@ #' @examples #' build_stratum("my_stratum_name", "PATH/TO/PROJECT/FOLDER/") build_stratum <- function(stratum_name, path = ".", order = 1) { - - #what if we dug into strata name more, pipeline becomes stratum? - # module becomes lamina? flows? - # Clean file name stratum_name <- clean_name(stratum_name) @@ -24,84 +20,82 @@ build_stratum <- function(stratum_name, path = ".", order = 1) { strata_toml <- fs::path(strata_folder, ".strata.toml") # Create folders - fs::dir_create(target_pipeline, recurse = TRUE) + fs::dir_create(target_stratum, recurse = TRUE) - #add a subfunction for creating main.R + # add a subfunction for creating main.R fs::file_create(fs::path(project_folder, "main.R")) - # .pipelines.toml if it doesn't exist - first_pipeline_setup <- !fs::file_exists(pipelines_toml) + # .strata.toml if it doesn't exist + first_stratum_setup <- !fs::file_exists(strata_toml) - # Create .pipelines.toml - if (first_pipeline_setup) { - initial_pipeline_toml( - path = pipelines_folder, - name = pipeline_name, - order = order #cant always assume this, need some logic + # Create .strata.toml + if (first_stratum_setup) { + initial_stratum_toml( + path = strata_folder, + name = stratum_name, + order = order # cant always assume this, need some logic ) } # read the .toml file - toml_snapshot <- snapshot_toml(pipelines_toml) + toml_snapshot <- snapshot_toml(strata_toml) - if (!first_pipeline_setup) { - current_pipelines <- + if (!first_stratum_setup) { + current_strata <- toml_snapshot |> dplyr::pull("name") - # update .pipelines.toml - if (!pipeline_name %in% current_pipelines) { + # update .strata.toml + if (!stratum_name %in% current_strata) { cat( paste0( - pipeline_name, " = { created = ", lubridate::today(), + stratum_name, " = { created = ", lubridate::today(), ", order = ", order, " }\n" ), - file = pipelines_toml, + file = strata_toml, append = TRUE ) - #trust but verify - toml_snapshot <- snapshot_toml(pipelines_toml) - - sorted_toml <- - manage_toml_order(toml_snapshot) + # trust but verify + toml_snapshot <- snapshot_toml(strata_toml) - if (!identical(sorted_toml, toml_snapshot)) { - rewrite_from_dataframe(sorted_toml, pipelines_toml) - } + sorted_toml <- + manage_toml_order(toml_snapshot) - base::invisible(target_pipeline) + if (!identical(sorted_toml, toml_snapshot)) { + rewrite_from_dataframe(sorted_toml, strata_toml) + } + base::invisible(target_stratum) } else { log_error( paste( - pipeline_name, + stratum_name, "already exists in", - fs::path(pipelines_folder) + fs::path(strata_folder) ) ) - } } - invisible(target_pipeline) + invisible(target_stratum) } -build_module <- function(module_name, pipeline_path, order = 1, skip_if_fail = FALSE ) { - #grab the strata structure +build_module <- function(module_name, stratum_path, order = 1, skip_if_fail = FALSE) { + # grab the strata structure module_name <- clean_name(module_name) - pipeline_path <- fs::path(pipeline_path) + stratum_path <- fs::path(stratum_path) - checkmate::assert_true(check_pipeline(pipeline_path)) + checkmate::assert_true(check_stratum(stratum_path)) - modules_path <- pipeline_path + modules_path <- stratum_path modules_toml <- fs::path(modules_path, ".modules.toml") - #create the new module's folder - new_module_path <- fs::path(pipeline_path, module_name) + # create the new module's folder + new_module_path <- fs::path(stratum_path, module_name) fs::dir_create(new_module_path) # .module.toml if it doesn't exist @@ -140,12 +134,12 @@ build_module <- function(module_name, pipeline_path, order = 1, skip_if_fail = F paste( module_name, "already exists in", - fs::path(pipeline_path, "modules") + fs::path(stratum_path, "modules") ) ) } - #trust but verify + # trust but verify toml_snapshot <- snapshot_toml(modules_toml) sorted_toml <- @@ -161,9 +155,9 @@ build_module <- function(module_name, pipeline_path, order = 1, skip_if_fail = F build_main <- function(project_path) { - project_path <- fs::path(project_path) - main_path <- fs::path(project_path, "main.R") - is_main <- fs::file_exists(main_path) + project_path <- fs::path(project_path) + main_path <- fs::path(project_path, "main.R") + is_main <- fs::file_exists(main_path) if (!is_main) { fs::file_create(main_path) cat( @@ -173,5 +167,3 @@ build_main <- function(project_path) { ) } } - - diff --git a/R/main.R b/R/main.R index 464f2b6..20c23a0 100644 --- a/R/main.R +++ b/R/main.R @@ -1,8 +1,8 @@ -find_pipelines <- function(project_path = NULL) { +find_strata <- function(project_path = NULL) { if (is.null(project_path)) stop("main() has no path") path <- fs::path(project_path) - toml_path <- fs::path(path, "pipelines/.pipelines.toml") + toml_path <- fs::path(path, "strata/.strata.toml") toml_path |> build_paths() @@ -62,13 +62,13 @@ main <- function(path = NULL) { build_execution_plan <- function(path) { path <- fs::path(path) - pipelines <- find_pipelines(path) - pipeline_name <- fs::path_file(pipelines) + strata <- find_strata(path) + stratum_name <- fs::path_file(strata) - #somehting like this? huh <- pipelines |> purrr::map(list) + #somehting like this? huh <- strata |> purrr::map(list) plan <- - pipelines |> + strata |> purrr::map(purrr::pluck) |> purrr::set_names() |> purrr::map(find_modules) @@ -83,7 +83,7 @@ build_execution_plan <- function(path) { } ) |> list_to_tibble("module_name") |> - dplyr::select(-"pipeline") + dplyr::select(-"stratum") script_names <- plan |> @@ -95,7 +95,7 @@ build_execution_plan <- function(path) { } ) |> list_to_tibble("script_name") |> - dplyr::select(-"pipeline") + dplyr::select(-"stratum") paths <- plan |> @@ -105,7 +105,7 @@ build_execution_plan <- function(path) { dplyr::bind_cols(script_names) |> dplyr::bind_cols(module_names) |> dplyr::mutate( - pipeline = fs::path_file(.data$pipeline) + stratum = fs::path_file(.data$stratum) ) } @@ -116,7 +116,7 @@ list_to_tibble <- function(list, name) { \(x,idx) { x |> dplyr::as_tibble() |> - dplyr::mutate(pipeline = idx) |> + dplyr::mutate(stratum = idx) |> dplyr::rename({{ name }} := .data$value) } ) |> diff --git a/R/source_wrappers.R b/R/source_wrappers.R index 2ac80d5..3a3e6d6 100644 --- a/R/source_wrappers.R +++ b/R/source_wrappers.R @@ -1,21 +1,21 @@ run_execution_plan <- function(execution_plan) { strata_start <- lubridate::now() - initial_pipeline <- execution_plan[1, ]$pipeline + initial_stratum <- execution_plan[1, ]$stratum initial_module <- execution_plan[1, ]$module_name log_message("Strata started") - log_message(paste("Pipeline:", initial_pipeline, "initialized")) + log_message(paste("Pipeline:", initial_stratum, "initialized")) log_message(paste("Module:", initial_module, "initialized")) for (row in seq_len(nrow(execution_plan))) { row_scope <- execution_plan[row, ] - row_pipeline <- row_scope$pipeline + row_stratum <- row_scope$stratum row_module <- row_scope$module_name - if (row_pipeline != initial_pipeline) { - log_message(paste("Pipeline:", row_pipeline, "initialized")) - initial_pipeline <- row_pipeline + if (row_stratum != initial_stratum) { + log_message(paste("Pipeline:", row_stratum, "initialized")) + initial_stratum <- row_stratum } if (row_module != initial_module) { @@ -37,6 +37,6 @@ run_execution_plan <- function(execution_plan) { } #TODO implement the following functions for adhoc work -# pick_pipeline() +# pick_stratum() # pick_module() diff --git a/R/toml.R b/R/toml.R index c4cc404..cdd80c0 100644 --- a/R/toml.R +++ b/R/toml.R @@ -1,13 +1,13 @@ # this needs way more cleanup but will work for now -initial_pipeline_toml <- function(path, name, order) { +initial_stratum_toml <- function(path, name, order) { path <- fs::path(path) - toml_file <- fs::path(path, ".pipelines.toml") + toml_file <- fs::path(path, ".strata.toml") fs::file_create(toml_file) writeLines( paste0( - "[pipelines]\n", + "[strata]\n", name, " = { created = ", lubridate::today(), ", order = ", order, " }" diff --git a/R/utils.R b/R/utils.R index bdfbae0..d838ca9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -5,27 +5,27 @@ clean_name <- function(name) { stringr::str_replace_all("[^[:alnum:]]|\\s", "_") } -check_pipeline <- function(pipeline_path) { +check_stratum <- function(stratum_path) { #force to fs::path - pipeline_path <- fs::path(pipeline_path) + stratum_path <- fs::path(stratum_path) strata_issue <- FALSE - # check if the pipeline exists - if (!fs::dir_exists(pipeline_path)) { + # check if the stratum exists + if (!fs::dir_exists(stratum_path)) { log_error( paste( - fs::path_file(pipeline_path), + fs::path_file(stratum_path), "does not exist" ) ) strata_issue <- TRUE } - # check if the pipeline has a modules folder - # if (!fs::dir_exists(fs::path(pipeline_path, "modules"))) { + # check if the stratum has a modules folder + # if (!fs::dir_exists(fs::path(stratum_path, "modules"))) { # log_error( # paste( - # fs::path_file(pipeline_path), + # fs::path_file(stratum_path), # "does not have a modules folder" # ) # ) diff --git a/man/build_pipeline.Rd b/man/build_pipeline.Rd deleted file mode 100644 index 886ed2e..0000000 --- a/man/build_pipeline.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/builders.R -\name{build_pipeline} -\alias{build_pipeline} -\title{Add a pipeline skeleton to your project space} -\usage{ -build_pipeline(pipeline_name, path = ".", order = 1) -} -\arguments{ -\item{pipeline_name}{A string that is the name of your pipeline} - -\item{path}{a path to where you want to drop your pipeline} - -\item{order}{the order of the pipeline} -} -\value{ -invisibly returns fs::path to pipeline -} -\description{ -Add a pipeline skeleton to your project space -} -\examples{ -build_pipeline("my_pipeline_name", "PATH/TO/PROJECT/FOLDER/") -} diff --git a/man/build_stratum.Rd b/man/build_stratum.Rd new file mode 100644 index 0000000..cc8e61e --- /dev/null +++ b/man/build_stratum.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/builders.R +\name{build_stratum} +\alias{build_stratum} +\title{Add a stratum skeleton to your project space} +\usage{ +build_stratum(stratum_name, path = ".", order = 1) +} +\arguments{ +\item{stratum_name}{A string that is the name of your stratum} + +\item{path}{a path to where you want to drop your stratum} + +\item{order}{the order of the stratum} +} +\value{ +invisibly returns fs::path to stratum +} +\description{ +Add a stratum skeleton to your project space +} +\examples{ +build_stratum("my_stratum_name", "PATH/TO/PROJECT/FOLDER/") +} diff --git a/man/strata-package.Rd b/man/strata-package.Rd index 46ea47a..4fa0527 100644 --- a/man/strata-package.Rd +++ b/man/strata-package.Rd @@ -6,7 +6,7 @@ \alias{strata-package} \title{strata: Simple Data Pipelines For Simple Automation} \description{ -Tools for a simple, human-focused pipeline framework for developers with only the most basic automation tool suite. The package is designed to get developers up and running quickly with the code they already have, and provide simple automation targets for use with tools like 'cron' or 'Task Scheduler'. +Tools for a simple, human-focused stratum framework for developers with only the most basic automation tool suite. The package is designed to get developers up and running quickly with the code they already have, and provide simple automation targets for use with tools like 'cron' or 'Task Scheduler'. } \seealso{ Useful links: From fb9e29d0c4789b939b54372bebc546b4ae2ad7a1 Mon Sep 17 00:00:00 2001 From: asenetcky Date: Thu, 24 Oct 2024 20:09:03 -0400 Subject: [PATCH 3/6] module/s to lamina/e --- R/builders.R | 44 +++++++++++++++++++++---------------------- R/main.R | 12 ++++++------ R/source_wrappers.R | 14 +++++++------- R/toml.R | 6 +++--- R/utils.R | 6 +++--- man/strata-package.Rd | 2 +- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/R/builders.R b/R/builders.R index c52122f..f755dda 100644 --- a/R/builders.R +++ b/R/builders.R @@ -83,74 +83,74 @@ build_stratum <- function(stratum_name, path = ".", order = 1) { } -build_module <- function(module_name, stratum_path, order = 1, skip_if_fail = FALSE) { +build_lamina <- function(lamina_name, stratum_path, order = 1, skip_if_fail = FALSE) { # grab the strata structure - module_name <- clean_name(module_name) + lamina_name <- clean_name(lamina_name) stratum_path <- fs::path(stratum_path) checkmate::assert_true(check_stratum(stratum_path)) - modules_path <- stratum_path - modules_toml <- fs::path(modules_path, ".modules.toml") + laminae_path <- stratum_path + laminae_toml <- fs::path(laminae_path, ".laminae.toml") - # create the new module's folder - new_module_path <- fs::path(stratum_path, module_name) - fs::dir_create(new_module_path) + # create the new lamina's folder + new_lamina_path <- fs::path(stratum_path, lamina_name) + fs::dir_create(new_lamina_path) - # .module.toml if it doesn't exist - if (!fs::file_exists(modules_toml)) { - initial_module_toml(modules_path) + # .lamina.toml if it doesn't exist + if (!fs::file_exists(laminae_toml)) { + initial_lamina_toml(laminae_path) } # read the .toml file - toml_snapshot <- snapshot_toml(modules_toml) + toml_snapshot <- snapshot_toml(laminae_toml) # read the .toml file if (!purrr::is_empty(toml_snapshot)) { - current_modules <- + current_laminae <- toml_snapshot |> dplyr::pull("name") } else { - current_modules <- "" + current_laminae <- "" } - # update .modules.toml - if (!module_name %in% current_modules) { + # update .laminae.toml + if (!lamina_name %in% current_laminae) { cat( paste0( - module_name, " = { created = ", lubridate::today(), + lamina_name, " = { created = ", lubridate::today(), ", order = ", order, ", skip_if_fail = ", stringr::str_to_lower(skip_if_fail), " }\n" ), - file = modules_toml, + file = laminae_toml, append = TRUE ) } else { log_error( paste( - module_name, + lamina_name, "already exists in", - fs::path(stratum_path, "modules") + fs::path(stratum_path, "laminae") ) ) } # trust but verify - toml_snapshot <- snapshot_toml(modules_toml) + toml_snapshot <- snapshot_toml(laminae_toml) sorted_toml <- manage_toml_order(toml_snapshot) if (!identical(sorted_toml, toml_snapshot)) { - rewrite_from_dataframe(sorted_toml, modules_toml) + rewrite_from_dataframe(sorted_toml, laminae_toml) } - base::invisible(new_module_path) + base::invisible(new_lamina_path) } diff --git a/R/main.R b/R/main.R index 20c23a0..92efc5a 100644 --- a/R/main.R +++ b/R/main.R @@ -8,8 +8,8 @@ find_strata <- function(project_path = NULL) { build_paths() } -find_modules <- function(path = ".") { - toml_path <- fs::path(path, ".modules.toml") +find_laminae <- function(path = ".") { + toml_path <- fs::path(path, ".laminae.toml") toml_path |> build_paths() |> @@ -71,9 +71,9 @@ build_execution_plan <- function(path) { strata |> purrr::map(purrr::pluck) |> purrr::set_names() |> - purrr::map(find_modules) + purrr::map(find_laminae) - module_names <- + lamina_names <- plan |> purrr::map( \(path) { @@ -82,7 +82,7 @@ build_execution_plan <- function(path) { ) } ) |> - list_to_tibble("module_name") |> + list_to_tibble("lamina_name") |> dplyr::select(-"stratum") script_names <- @@ -103,7 +103,7 @@ build_execution_plan <- function(path) { paths |> dplyr::bind_cols(script_names) |> - dplyr::bind_cols(module_names) |> + dplyr::bind_cols(lamina_names) |> dplyr::mutate( stratum = fs::path_file(.data$stratum) ) diff --git a/R/source_wrappers.R b/R/source_wrappers.R index 3a3e6d6..d744906 100644 --- a/R/source_wrappers.R +++ b/R/source_wrappers.R @@ -2,15 +2,15 @@ run_execution_plan <- function(execution_plan) { strata_start <- lubridate::now() initial_stratum <- execution_plan[1, ]$stratum - initial_module <- execution_plan[1, ]$module_name + initial_lamina <- execution_plan[1, ]$lamina_name log_message("Strata started") log_message(paste("Pipeline:", initial_stratum, "initialized")) - log_message(paste("Module:", initial_module, "initialized")) + log_message(paste("Module:", initial_lamina, "initialized")) for (row in seq_len(nrow(execution_plan))) { row_scope <- execution_plan[row, ] row_stratum <- row_scope$stratum - row_module <- row_scope$module_name + row_lamina <- row_scope$lamina_name if (row_stratum != initial_stratum) { @@ -18,9 +18,9 @@ run_execution_plan <- function(execution_plan) { initial_stratum <- row_stratum } - if (row_module != initial_module) { - log_message(paste("Module:", row_module, "initialized")) - initial_module <- row_module + if (row_lamina != initial_lamina) { + log_message(paste("Module:", row_lamina, "initialized")) + initial_lamina <- row_lamina } @@ -38,5 +38,5 @@ run_execution_plan <- function(execution_plan) { #TODO implement the following functions for adhoc work # pick_stratum() -# pick_module() +# pick_lamina() diff --git a/R/toml.R b/R/toml.R index cdd80c0..ef8b0a4 100644 --- a/R/toml.R +++ b/R/toml.R @@ -17,13 +17,13 @@ initial_stratum_toml <- function(path, name, order) { base::invisible(toml_file) } -initial_module_toml <- function(path) { +initial_lamina_toml <- function(path) { path <- fs::path(path) - toml_file <- fs::path(path, ".modules.toml") + toml_file <- fs::path(path, ".laminae.toml") fs::file_create(toml_file) writeLines( - paste0("[modules]"), + paste0("[laminae]"), toml_file ) base::invisible(toml_file) diff --git a/R/utils.R b/R/utils.R index d838ca9..bfbd8b8 100644 --- a/R/utils.R +++ b/R/utils.R @@ -21,12 +21,12 @@ check_stratum <- function(stratum_path) { strata_issue <- TRUE } - # check if the stratum has a modules folder - # if (!fs::dir_exists(fs::path(stratum_path, "modules"))) { + # check if the stratum has a laminae folder + # if (!fs::dir_exists(fs::path(stratum_path, "laminae"))) { # log_error( # paste( # fs::path_file(stratum_path), - # "does not have a modules folder" + # "does not have a laminae folder" # ) # ) # strata_issue <- TRUE diff --git a/man/strata-package.Rd b/man/strata-package.Rd index 4fa0527..46ea47a 100644 --- a/man/strata-package.Rd +++ b/man/strata-package.Rd @@ -6,7 +6,7 @@ \alias{strata-package} \title{strata: Simple Data Pipelines For Simple Automation} \description{ -Tools for a simple, human-focused stratum framework for developers with only the most basic automation tool suite. The package is designed to get developers up and running quickly with the code they already have, and provide simple automation targets for use with tools like 'cron' or 'Task Scheduler'. +Tools for a simple, human-focused pipeline framework for developers with only the most basic automation tool suite. The package is designed to get developers up and running quickly with the code they already have, and provide simple automation targets for use with tools like 'cron' or 'Task Scheduler'. } \seealso{ Useful links: From 72c45d77c852bfa8f56684a97504d1028fd27d8c Mon Sep 17 00:00:00 2001 From: asenetcky Date: Thu, 24 Oct 2024 20:11:29 -0400 Subject: [PATCH 4/6] code format and lint --- R/logging.R | 1 - R/main.R | 24 ++++++++-------- R/source_wrappers.R | 4 +-- R/strata.R | 4 +-- R/toml.R | 67 ++++++++++++++++++++++----------------------- R/utils.R | 2 +- 6 files changed, 47 insertions(+), 55 deletions(-) diff --git a/R/logging.R b/R/logging.R index 1b58d73..aabc3a0 100644 --- a/R/logging.R +++ b/R/logging.R @@ -10,7 +10,6 @@ #' @examples #' log_message("This is an info message", "INFO", "OUT") log_message <- function(message, level = "INFO", out_or_err = "OUT") { - # check for stdout or stderr checkmate::assert_choice(out_or_err, c("OUT", "ERR")) timestamp <- lubridate::now() diff --git a/R/main.R b/R/main.R index 92efc5a..41c5b0b 100644 --- a/R/main.R +++ b/R/main.R @@ -44,7 +44,7 @@ build_paths <- function(toml_path) { dplyr::pull(.data$paths) } ) |> - purrr::list_c() + purrr::list_c() } main <- function(path = NULL) { @@ -56,7 +56,6 @@ main <- function(path = NULL) { build_execution_plan(path) run_execution_plan(execution_plan) - } build_execution_plan <- function(path) { @@ -66,7 +65,7 @@ build_execution_plan <- function(path) { stratum_name <- fs::path_file(strata) - #somehting like this? huh <- strata |> purrr::map(list) + # somehting like this? huh <- strata |> purrr::map(list) plan <- strata |> purrr::map(purrr::pluck) |> @@ -76,12 +75,12 @@ build_execution_plan <- function(path) { lamina_names <- plan |> purrr::map( - \(path) { - fs::path_file( - fs::path_dir(path) - ) - } - ) |> + \(path) { + fs::path_file( + fs::path_dir(path) + ) + } + ) |> list_to_tibble("lamina_name") |> dplyr::select(-"stratum") @@ -99,7 +98,7 @@ build_execution_plan <- function(path) { paths <- plan |> - list_to_tibble("path") + list_to_tibble("path") paths |> dplyr::bind_cols(script_names) |> @@ -107,15 +106,14 @@ build_execution_plan <- function(path) { dplyr::mutate( stratum = fs::path_file(.data$stratum) ) - } list_to_tibble <- function(list, name) { list |> purrr::imap( - \(x,idx) { + \(x, idx) { x |> - dplyr::as_tibble() |> + dplyr::as_tibble() |> dplyr::mutate(stratum = idx) |> dplyr::rename({{ name }} := .data$value) } diff --git a/R/source_wrappers.R b/R/source_wrappers.R index d744906..78416d5 100644 --- a/R/source_wrappers.R +++ b/R/source_wrappers.R @@ -25,7 +25,6 @@ run_execution_plan <- function(execution_plan) { source(row_scope$path) - } @@ -36,7 +35,6 @@ run_execution_plan <- function(execution_plan) { ) } -#TODO implement the following functions for adhoc work +# TODO implement the following functions for adhoc work # pick_stratum() # pick_lamina() - diff --git a/R/strata.R b/R/strata.R index da52f93..32fc015 100644 --- a/R/strata.R +++ b/R/strata.R @@ -1,9 +1,7 @@ - survey_strata <- function(project_path) { - #force to fs::path + # force to fs::path project_path <- fs::path(project_path) # read the .tomls, and report out info on the strata project - } diff --git a/R/toml.R b/R/toml.R index ef8b0a4..f7d03e8 100644 --- a/R/toml.R +++ b/R/toml.R @@ -55,37 +55,38 @@ manage_toml_order <- function(toml_snapshot) { !dplyr::n_distinct(toml_snapshot$order) == base::nrow(toml_snapshot) if (duplicate_orders) { - toml_name <- paste0(".", unique(toml_snapshot$type), ".toml") - duped_orders <- + toml_name <- paste0(".", unique(toml_snapshot$type), ".toml") + duped_orders <- toml_snapshot |> dplyr::count(order) |> - dplyr::filter(.data$n > 1) |> + dplyr::filter(.data$n > 1) |> dplyr::pull(order) - without_dupes <- - toml_snapshot |> - dplyr::filter(!order %in% duped_orders) |> - dplyr::arrange(order) |> - dplyr::mutate(order = dplyr::row_number()) - - max_order <- max(without_dupes$order, 0) - - with_dupes <- - toml_snapshot |> - dplyr::filter(order %in% duped_orders) |> - dplyr::arrange(dplyr::across(dplyr::starts_with("name"))) |> - dplyr::mutate(order = max_order + dplyr::row_number()) - - toml_snapshot <- - dplyr::bind_rows(without_dupes, with_dupes) - - log_message( - paste( - "Duplicate orders found in the", - toml_name, - "file, reordering" - ), - "WARN") + without_dupes <- + toml_snapshot |> + dplyr::filter(!order %in% duped_orders) |> + dplyr::arrange(order) |> + dplyr::mutate(order = dplyr::row_number()) + + max_order <- max(without_dupes$order, 0) + + with_dupes <- + toml_snapshot |> + dplyr::filter(order %in% duped_orders) |> + dplyr::arrange(dplyr::across(dplyr::starts_with("name"))) |> + dplyr::mutate(order = max_order + dplyr::row_number()) + + toml_snapshot <- + dplyr::bind_rows(without_dupes, with_dupes) + + log_message( + paste( + "Duplicate orders found in the", + toml_name, + "file, reordering" + ), + "WARN" + ) } toml_snapshot |> dplyr::arrange(order) |> @@ -93,12 +94,12 @@ manage_toml_order <- function(toml_snapshot) { } backup_toml <- function(toml_path) { - file_root <- fs::path_dir(toml_path) + file_root <- fs::path_dir(toml_path) file_name <- fs::path_file(toml_path) |> stringr::str_replace("\\.toml", "\\.bak") - fs::file_copy(toml_path, fs::path(file_root, file_name), overwrite = TRUE) + fs::file_copy(toml_path, fs::path(file_root, file_name), overwrite = TRUE) log_message( paste( @@ -116,7 +117,7 @@ write_toml_lines <- function(toml_content, toml_path) { toml_path <- fs::path(toml_path) toml_type <- base::unique(toml_content$type) - #TODO make cleaner + # TODO make cleaner names <- toml_content |> dplyr::select(dplyr::any_of("name")) @@ -142,7 +143,7 @@ write_toml_lines <- function(toml_content, toml_path) { dplyr::tibble( skip_if_fail = paste0(", skip_if_fail = ", skip_if_fails$skip_if_fail) - ) + ) } lines <- @@ -176,7 +177,6 @@ write_toml_lines <- function(toml_content, toml_path) { ) } ) - } @@ -186,7 +186,7 @@ rewrite_from_dataframe <- function(toml_snapshot, toml_path) { backup_toml(toml_path) fs::file_delete(toml_path) - #rewrite toml + # rewrite toml new_toml <- toml_snapshot |> dplyr::mutate( @@ -199,4 +199,3 @@ rewrite_from_dataframe <- function(toml_snapshot, toml_path) { write_toml_lines(new_toml, toml_path) invisible(toml_path) } - diff --git a/R/utils.R b/R/utils.R index bfbd8b8..fca3505 100644 --- a/R/utils.R +++ b/R/utils.R @@ -6,7 +6,7 @@ clean_name <- function(name) { } check_stratum <- function(stratum_path) { - #force to fs::path + # force to fs::path stratum_path <- fs::path(stratum_path) strata_issue <- FALSE From 9ca038a3e378ad8484355b7f09ffc30f4c60b46c Mon Sep 17 00:00:00 2001 From: asenetcky Date: Thu, 24 Oct 2024 20:31:19 -0400 Subject: [PATCH 5/6] document main() --- NAMESPACE | 1 + R/main.R | 35 ++++++++++++++++++++++++----------- man/main.Rd | 22 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 man/main.Rd diff --git a/NAMESPACE b/NAMESPACE index 655f9a3..7eb4413 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(build_stratum) export(log_error) export(log_message) export(log_total_time) +export(main) import(rlang) importFrom(glue,glue) importFrom(lifecycle,deprecated) diff --git a/R/main.R b/R/main.R index 41c5b0b..b729bb9 100644 --- a/R/main.R +++ b/R/main.R @@ -1,3 +1,27 @@ +#' Entry point into your strata project and automation target +#' +#' @param project_path A path to automation project folder +#' +#' @return invisible execution plan +#' @export +#' +#' @examples +#'\dontrun{ +#' main("/PATH/TO/PROJECT/FOLDER") +#'} +main <- function(project_path = NULL) { + if (is.null(project_path)) stop("main() has no path") + + project_path <- fs::path(project_path) + + execution_plan <- + build_execution_plan(project_path) + + run_execution_plan(execution_plan) + + invisible(execution_plan) +} + find_strata <- function(project_path = NULL) { if (is.null(project_path)) stop("main() has no path") @@ -47,17 +71,6 @@ build_paths <- function(toml_path) { purrr::list_c() } -main <- function(path = NULL) { - if (is.null(path)) stop("main() has no path") - - path <- fs::path(path) - - execution_plan <- - build_execution_plan(path) - - run_execution_plan(execution_plan) -} - build_execution_plan <- function(path) { path <- fs::path(path) diff --git a/man/main.Rd b/man/main.Rd new file mode 100644 index 0000000..85e1848 --- /dev/null +++ b/man/main.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/main.R +\name{main} +\alias{main} +\title{Entry point into your strata project and automation target} +\usage{ +main(project_path = NULL) +} +\arguments{ +\item{project_path}{A path to automation project folder} +} +\value{ +invisible execution plan +} +\description{ +Entry point into your strata project and automation target +} +\examples{ +\dontrun{ +main("/PATH/TO/PROJECT/FOLDER") +} +} From e69ffd15469fe959a4ce1d74383ffb53cf089477 Mon Sep 17 00:00:00 2001 From: asenetcky Date: Thu, 24 Oct 2024 20:41:53 -0400 Subject: [PATCH 6/6] document build_* functions --- NAMESPACE | 1 + R/builders.R | 30 ++++++++++++++++++++++-------- R/main.R | 2 -- man/build_lamina.Rd | 28 ++++++++++++++++++++++++++++ man/build_stratum.Rd | 8 +++++--- 5 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 man/build_lamina.Rd diff --git a/NAMESPACE b/NAMESPACE index 7eb4413..9dfd0ae 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(build_lamina) export(build_stratum) export(log_error) export(log_message) diff --git a/R/builders.R b/R/builders.R index f755dda..1963f67 100644 --- a/R/builders.R +++ b/R/builders.R @@ -1,14 +1,16 @@ #' Add a stratum skeleton to your project space #' -#' @param stratum_name A string that is the name of your stratum -#' @param path a path to where you want to drop your stratum -#' @param order the order of the stratum +#' @param stratum_name Name of your stratum +#' @param path A path to where you want to drop your stratum +#' @param order The order of the stratum #' #' @return invisibly returns fs::path to stratum #' @export #' #' @examples +#'\dontrun{ #' build_stratum("my_stratum_name", "PATH/TO/PROJECT/FOLDER/") +#'} build_stratum <- function(stratum_name, path = ".", order = 1) { # Clean file name stratum_name <- clean_name(stratum_name) @@ -37,7 +39,6 @@ build_stratum <- function(stratum_name, path = ".", order = 1) { ) } - # read the .toml file toml_snapshot <- snapshot_toml(strata_toml) @@ -83,7 +84,24 @@ build_stratum <- function(stratum_name, path = ".", order = 1) { } +#' Add a lamina skeleton to your project space +#' +#' @param lamina_name Name of your Lamina +#' @param stratum_path Path to the parent stratum +#' @param order Execution order inside of stratum +#' @param skip_if_fail Skip this lamina if it fails +#' +#' @return invisibly returns fs::path to lamina +#' @export +#' +#' @examples +#'\dontrun{ +#' build_lamina("my_lamina_name", "PATH/TO/STRATUM/FOLDER/") +#'} build_lamina <- function(lamina_name, stratum_path, order = 1, skip_if_fail = FALSE) { + #TODO replace stratum_path with stratum_name + # to make it more user friendly + # grab the strata structure lamina_name <- clean_name(lamina_name) stratum_path <- fs::path(stratum_path) @@ -106,8 +124,6 @@ build_lamina <- function(lamina_name, stratum_path, order = 1, skip_if_fail = FA # read the .toml file toml_snapshot <- snapshot_toml(laminae_toml) - # read the .toml file - if (!purrr::is_empty(toml_snapshot)) { current_laminae <- toml_snapshot |> @@ -116,7 +132,6 @@ build_lamina <- function(lamina_name, stratum_path, order = 1, skip_if_fail = FA current_laminae <- "" } - # update .laminae.toml if (!lamina_name %in% current_laminae) { cat( @@ -149,7 +164,6 @@ build_lamina <- function(lamina_name, stratum_path, order = 1, skip_if_fail = FA rewrite_from_dataframe(sorted_toml, laminae_toml) } - base::invisible(new_lamina_path) } diff --git a/R/main.R b/R/main.R index b729bb9..c1d5d6a 100644 --- a/R/main.R +++ b/R/main.R @@ -77,8 +77,6 @@ build_execution_plan <- function(path) { strata <- find_strata(path) stratum_name <- fs::path_file(strata) - - # somehting like this? huh <- strata |> purrr::map(list) plan <- strata |> purrr::map(purrr::pluck) |> diff --git a/man/build_lamina.Rd b/man/build_lamina.Rd new file mode 100644 index 0000000..88033ab --- /dev/null +++ b/man/build_lamina.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/builders.R +\name{build_lamina} +\alias{build_lamina} +\title{Add a lamina skeleton to your project space} +\usage{ +build_lamina(lamina_name, stratum_path, order = 1, skip_if_fail = FALSE) +} +\arguments{ +\item{lamina_name}{Name of your Lamina} + +\item{stratum_path}{Path to the parent stratum} + +\item{order}{Execution order inside of stratum} + +\item{skip_if_fail}{Skip this lamina if it fails} +} +\value{ +invisibly returns fs::path to lamina +} +\description{ +Add a lamina skeleton to your project space +} +\examples{ +\dontrun{ +build_lamina("my_lamina_name", "PATH/TO/STRATUM/FOLDER/") +} +} diff --git a/man/build_stratum.Rd b/man/build_stratum.Rd index cc8e61e..5c56361 100644 --- a/man/build_stratum.Rd +++ b/man/build_stratum.Rd @@ -7,11 +7,11 @@ build_stratum(stratum_name, path = ".", order = 1) } \arguments{ -\item{stratum_name}{A string that is the name of your stratum} +\item{stratum_name}{Name of your stratum} -\item{path}{a path to where you want to drop your stratum} +\item{path}{A path to where you want to drop your stratum} -\item{order}{the order of the stratum} +\item{order}{The order of the stratum} } \value{ invisibly returns fs::path to stratum @@ -20,5 +20,7 @@ invisibly returns fs::path to stratum Add a stratum skeleton to your project space } \examples{ +\dontrun{ build_stratum("my_stratum_name", "PATH/TO/PROJECT/FOLDER/") } +}