Title: | Helper Functions for Use with "ProjectTemplate" |
---|---|
Description: | Utility functions produced specifically for (but not limited to) working with 'ProjectTemplate' data pipelines. This package helps to quickly create and manage sequentially numbered scripts, quickly set up logging with 'log4r' and functions to help debug and monitor procedures. |
Authors: | Rich Leyshon [aut, cph, cre], Iris Simmons [ctb] |
Maintainer: | Rich Leyshon <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.2 |
Built: | 2025-02-12 03:40:51 UTC |
Source: | https://github.com/r-leyshon/ptspotter |
This function is used to increment / decrease sequential scripts within the specified directory, allowing efficient adjustment of script sequence for additional or removed files.
adj_file_nos(target, directory = NULL, action = "up", step = 1)
adj_file_nos(target, directory = NULL, action = "up", step = 1)
target |
Required. The number in the sequential scripts to begin the adjustment. Use single digits only. The adjustment will affect script with that leading digit and greater. |
directory |
The directory holding the sequential scripts. |
action |
Defaults to "up". Whether to adjust file numbers up or down. |
step |
Defaults to 1. The step by which to increment or decrement the file numbering. |
Renumbers filenames in the specified directory, according to the specified action. Only affects the target file and above.
seq_file_ops(n = 10, target_dir = "munge") # Increase files numbered 6 and above by 1 adj_file_nos(target = 6, directory = "munge") # Increase above target files by a further 2 adj_file_nos(target = 6, directory = "munge", step = 2) # Use step = "down" to restore original sequence adj_file_nos(target = 6, directory = "munge", action = "down", step = 3) # writing books or websites: seq_file_ops(n = 5, target_dir = "images", filetype = "png") # adjust by decimals adj_file_nos(target = 1, directory = "images", step = 0.1) # tidying up environment unlink(c("munge", "images"), recursive = TRUE)
seq_file_ops(n = 10, target_dir = "munge") # Increase files numbered 6 and above by 1 adj_file_nos(target = 6, directory = "munge") # Increase above target files by a further 2 adj_file_nos(target = 6, directory = "munge", step = 2) # Use step = "down" to restore original sequence adj_file_nos(target = 6, directory = "munge", action = "down", step = 3) # writing books or websites: seq_file_ops(n = 5, target_dir = "images", filetype = "png") # adjust by decimals adj_file_nos(target = 1, directory = "images", step = 0.1) # tidying up environment unlink(c("munge", "images"), recursive = TRUE)
Assigns the necessary global scope objects for logging with "log4r".
log_enable( logfile_loc = NULL, pos = 1, logger_nm = my_logger, appender_nm = file_app )
log_enable( logfile_loc = NULL, pos = 1, logger_nm = my_logger, appender_nm = file_app )
logfile_loc |
The path to the logfile. Suggested use "logs/logfile.txt". |
pos |
The environment which to assign pipeline_message. Defaults to 1, equivalent to the .GlobalEnv. |
logger_nm |
What to call the logger. Provide unquoted strings with no spaces. Defaults to my_logger. |
appender_nm |
What to call the appender function. Provide unquoted strings with no spaces. Defaults to file_app. |
Creates logger and file appender.
# create logging infrastructure log_file_ops(dir_path = "logs/logfile.txt") # enable logging log_enable(logfile_loc = "logs/logfile.txt") # tidy up environment unlink("logs", recursive = TRUE)
# create logging infrastructure log_file_ops(dir_path = "logs/logfile.txt") # enable logging log_enable(logfile_loc = "logs/logfile.txt") # tidy up environment unlink("logs", recursive = TRUE)
Create the necessary file infrastructure to efficiently start logging with "log4r".
log_file_ops(dir_path = NULL, logfile_nm = "logfile")
log_file_ops(dir_path = NULL, logfile_nm = "logfile")
dir_path |
The name of the folder in which the logfile should be saved. Creates the folder if required. |
logfile_nm |
Provide a name for the logfile. Do not include suffix. Defaults to "logfile". |
Creates log directory and log file if required. Calls log_enable() to assign necessary logging objects in specified scope.
log_file_ops(dir_path = "logs") unlink("logs", recursive = TRUE)
log_file_ops(dir_path = "logs") unlink("logs", recursive = TRUE)
Used to log memory allocation at points during sequential script execution.
memory_report()
memory_report()
Performs garbage collection then messages memory size and script name currently being executed.
try(memory_report())
try(memory_report())
Quickly create the required number of sequentially labelled files.
seq_file_ops(n, target_dir = NULL, filetype = "R", force = FALSE)
seq_file_ops(n, target_dir = NULL, filetype = "R", force = FALSE)
n |
The number of files to create. Also accepts numerical vector. |
target_dir |
Directory to create files. Creates the directory if file.exists(target_dir) evaluates to FALSE. |
filetype |
The suffix to append the filename. Defaults to ".R". |
force |
Defaults to FALSE. If set to TRUE, seq_file_ops will overwrite any pre-existing files that match the write filenames asked for. |
Write a series of sequentially numbered files within a specified directory. Creates the directory if required.
seq_file_ops(n = 10, target_dir = "munge") seq_file_ops(n = c(1, 3:8, 10), target_dir = "complex_vector") # if force == FALSE, pre-existing numbered scripts will not be overwritten # only 02-.R and 09-.R are written below seq_file_ops(10, target_dir = "complex_vector") unlink("munge", recursive = TRUE) unlink("complex_vector", recursive = TRUE)
seq_file_ops(n = 10, target_dir = "munge") seq_file_ops(n = c(1, 3:8, 10), target_dir = "complex_vector") # if force == FALSE, pre-existing numbered scripts will not be overwritten # only 02-.R and 09-.R are written below seq_file_ops(10, target_dir = "complex_vector") unlink("munge", recursive = TRUE) unlink("complex_vector", recursive = TRUE)
Used to interrupt sequential script execution while testing or debugging.
Outputs an auditory signal and breaks sequential script execution,
identifying the script at which execution was interrupted.
Is a Sys.time() object is passed to start_time
, messages the elapsed time.
wrap_up(start_time = NULL)
wrap_up(start_time = NULL)
start_time |
Optional POSIXct object, created by assigning Sys.time()
to an object prior to executing |
Interrupts sequential script execution with an auditory signal. Logs the elapsed time if start_time is used, outputs the script location.
# halt execution with no timing try(wrap_up()) # create timing checkpoint s_time <- Sys.time() # halt execution with timing try(wrap_up(s_time))
# halt execution with no timing try(wrap_up()) # create timing checkpoint s_time <- Sys.time() # halt execution with timing try(wrap_up(s_time))