_targets_commands.R

# https://amitlevinson.com/blog/automated-plot-with-github-actions/ ----

# https://petrkajzar.eu/en/2021/data-rpkg.html

#   Install Package:           'Cmd + Shift + B'
#   Check Package:             'Cmd + Shift + E'
#   Test Package:              'Cmd + Shift + T'

# https://dmi3kno.github.io/polite/
# https://pins.rstudio.com/articles/use-cases/automate-dataset-updates.html
#

# https://cran.r-project.org/web/packages/renv/vignettes/renv.html
#
# To set up package.
# library(usethis) ; usethis::use_data_raw("fdata")
#
# usethis::use_github() # Initial push to git hub
#




library(targets) ; library(tidyverse) # ---- # run `tar_make()` or `tar_make_clustermq()`

# https://community.rstudio.com/t/targets-workflow-management-error-when-repeats-pulling-coefficients-of-tidyverse-framework/83485
# tar_script() creates a _targets.R file, which is where you declare you write functions and options and create your targets with tar_targets(), declare pipeline with tar_plan/tar_pipeline()
tar_edit() # open `_targets.R` for editing
# https://github.com/wlandau/targets-minimal

# targets in parallel ----
# RStudio forked processing ('multicore') not supported cos ##unstable##
# parallelly::supportsMulticore() # control forked processing,
# to silence this warning
# targets::tar_make_clustermq(workers = 2L)

# https://wlandau.github.io/targets/reference/index.html ----
library(tarchetypes) ; library(targets)
tar_validate()
tar_manifest() # check targets configuration
tar_sitrep() # Show the cue-by-cue status of each target.
tar_glimpse() # alt cmd g how targets co-depend - relationships via static code analysis
# tar_manifest(fields = "name") %>% mutate(name %>% str_detect('report') )
tar_visnetwork(targets_only=FALSE, label = c("time", "size", "branches") ) # visualises your pipeline as a graph network
tar_network() # vertices / edges of pipeline dependency graph.
try(tar_make()) # cache outputs & metadata in _targets/ directory -- tar_read() / tar_load()
tar_meta(fields = c('name', 'seconds', 'warnings', 'error', 'type', 'format', 'path')) %>% arrange(error, warnings, desc(seconds))
tar_meta(fields = 'warnings') %>% drop_na() %>% pull() # tar_meta(names = starts_with("churn"), fields = path)

tar_progress() # Read the target progress of the latest run of the pipeline.
tar_outdated() # targets to be updated - re-make it
tar_objects() # List saved targets
tar_prune() # Remove targets that are no longer part of the pipeline.
tar_deduplicate() # Deduplicate meta and progress databases.
tar_delete("init_port") # Delete target return values.
tar_invalidate(c("r.ls.regime")) # Invalidate targets and global objects in the metadata.
tar_destroy() # Start fresh. Destroy some/all of the _targets/ data store in getwd()
tar_deps({ x <- function() 2-4 }) # detects commands dependencies / to run code analysis & see dependencies


# tar_option_set(error="workspace")
# on err: workspace image file in `_targets/workspaces/`.
# (Or, tar_option_set(workspace = c("target1", "target2")) - always save workspaces for specific targets.
tar_meta(fields = c("error", "warnings")) %>% drop_na(warnings) %>% pull(warnings)
tar_meta(ends_with('r.ls.regime'), fields = c('name', 'seconds', 'bytes', 'path')) %>% t
tar_meta(fields = 'error') %>% na.omit() ; list.files("_targets/workspaces")
tar_workspaces() # List saved target workspaces in _targets/workspaces
tar_workspace(README) # environment of failed target command - reproduce error
tar_traceback(r.ls.regime) # Get a target's traceback
# exists("train_control") ; exists("fit_glmnet") # false for failed target.

# tar_undebug() # remove (large) workspace files
# debug() debugonce() undebug() browse() # debugging functions utilities
# https://rstats.wtf/debugging-r-code.html # interactive debugging
# debugonce(<<function>>) Shift+F9 set breakpt == browser(), 'where' stack trace, 's' step into `n` next line, `c` next breakpoint `Q` to exit
# Or debug interactively while `tar_make()`
# tar_option_set(debug = "<<function name>>", cue = tar_cue(mode = "never")) then tar_make(callr_function = NULL) in the R console

# library(rmarkdown) ; render("report.Rmd") ; browseURL("report.Rmd")
# unlink("report.html")
JohnGavin/fdata documentation built on Jan. 29, 2021, 1:38 p.m.