Skip to content

Commit

Permalink
Duplicate setup method from pipeline in Quarto docs (#93)
Browse files Browse the repository at this point in the history
* Fixed minicipality name

* debugged changed names

* Started editing actual document

* Got a running document.

* Updated packages

* Removed Packages v2

* Started modifying Dates and text

* Continuing to modify dates

* pre-linting changes

* Modified to improve linting things

* Removed Personal Path and minor changes.

* Switched to Run_Triad

* Added run_triad change

* Added Text

* Fixed City Name

* Fixing panel-tabset

* Pre stash push

* Added noctua

* restored correct packages

* Removed Enters

* Syler

* re-ordered document

* Reordered libraries

* Remove Old Files

* Added libraries

* libraries

* Updated Description and Lock File

* added dependencies for DT

* re-upload changed lock file

* Restore lockfile dependencies

* Add reporting profile file to .dockerignore

* removed ignore_sigpipes()

* don't know alphabet

* re-ordered description

* Add missing dependencies to DESCRIPTION and lockfile

* Add .rmarkdown files to .gitignore

* Re-add sigpipe catch

* Update Quarto deps

* Add relative imports and libraries using here calls

* Revert reporting renv.lock

* Add conditional assignment for Quarto doc context

* Cleanup and comment setup code

---------

Co-authored-by: Damonamajor <[email protected]>
Co-authored-by: Damonamajor <[email protected]>
Co-authored-by: Michael Wagner <[email protected]>
  • Loading branch information
4 people authored Dec 19, 2023
1 parent 1fd01be commit 4bcb8ae
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 50 deletions.
37 changes: 23 additions & 14 deletions R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ options(
tidymodels.dark = TRUE, # Tidymodels CV output compatible with dark theme
dplyr.summarise.inform = FALSE, # Disable messages when aggregating
scipen = 99, # Disable scientific notation
knitr.kable.NA = "", # Replace NA with empty string in knitr::kable
java.parameters = "-Xmx10g" # Pre-allocate memory for Java JDBC driver
knitr.kable.NA = "" # Replace NA with empty string in knitr::kable
)

# Load R pipeline dependencies from the Depends: key in the DESCRIPTION file.
# Any new pipeline dependencies should be added there
suppressPackageStartupMessages({
purrr::walk(
strsplit(yaml::read_yaml("DESCRIPTION")$Depends, ", ")[[1]],
strsplit(yaml::read_yaml(here::here("DESCRIPTION"))$Depends, ", ")[[1]],
library,
character.only = TRUE
)
Expand Down Expand Up @@ -45,8 +44,15 @@ source(here::here("R", "helpers.R"))
# Initialize a dictionary of file paths. See misc/file_dict.csv for details
paths <- model_file_dict()

# Load the parameters file containing the run settings
params <- read_yaml("params.yaml")
# Load the parameters file containing the run settings. The conditional here
# detects rendering in a Quarto/RMarkdown document and assigns to `model_params`
# instead, since `params` is a reserved variable name in Quarto
if (knitr::is_html_output() || knitr::is_latex_output()) {
params_obj_name <- "model_params"
} else {
params_obj_name <- "params"
}
assign(params_obj_name, read_yaml(here("params.yaml")))

# Get the number of available physical cores to use for multi-threading
# Lightgbm docs recommend using only real cores, not logical
Expand All @@ -55,12 +61,15 @@ num_threads <- parallel::detectCores(logical = FALSE)

# Override CV toggle, SHAP toggle, and S3 upload set in params.yaml.
# Used to disable certain features for CI or limited runs
cv_enable <- as.logical(
Sys.getenv("CV_ENABLE_OVERRIDE", unset = params$toggle$cv_enable)
)
shap_enable <- as.logical(
Sys.getenv("SHAP_ENABLE_OVERRIDE", unset = params$toggle$shap_enable)
)
upload_enable <- as.logical(
Sys.getenv("UPLOAD_ENABLE_OVERRIDE", unset = params$toggle$upload_enable)
)
cv_enable <- as.logical(Sys.getenv(
"CV_ENABLE_OVERRIDE",
unset = get(params_obj_name)$toggle$cv_enable
))
shap_enable <- as.logical(Sys.getenv(
"SHAP_ENABLE_OVERRIDE",
unset = get(params_obj_name)$toggle$shap_enable
))
upload_enable <- as.logical(Sys.getenv(
"UPLOAD_ENABLE_OVERRIDE",
unset = get(params_obj_name)$toggle$upload_enable
))
52 changes: 16 additions & 36 deletions reports/performance.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,25 @@ format:
fontsize: 12pt
editor: source
params:
run_id: 2023-12-19-recursing-jacob
run_id: '2023-12-19-vigilant-jacob'
year: '2023'
---

```{r setup}
options(knitr.kable.NA = "", scipen = 99, width = 150)
# Load necessary libraries
library(arrow)
library(ccao)
library(brio)
library(DBI)
library(decor)
library(desc)
library(dplyr)
library(DT)
library(ggplot2)
library(glue)
library(grid)
library(gridExtra)
library(gtools)
library(here)
library(htmltools)
library(kableExtra)
library(leaflet)
library(plotly)
library(purrr)
library(recipes)
library(scales)
library(sf)
library(skimr)
library(stringr)
library(tableone)
library(tidyr)
library(tools)
source(here("R", "helpers.R"))
# TODO: Catch for weird arrow bug with SIGPIPE. Need to permanently fix later
# Load list of helper files and main libraries
purrr::walk(list.files(here::here("R"), "\\.R$", full.names = TRUE), source)
# Load reporting-only libraries
suppressPackageStartupMessages({
reporting_libs <- "Config/renv/profiles/reporting/dependencies"
purrr::walk(
strsplit(yaml::read_yaml(here::here("DESCRIPTION"))[[reporting_libs]], ", ")[[1]],
library,
character.only = TRUE
)
})
# TODO: Catch for weird Arrow bug with SIGPIPE. Need to permanently fix later
# https://github.com/apache/arrow/issues/32026
cpp11::cpp_source(code = "
#include <csignal>
Expand All @@ -63,7 +44,7 @@ cpp11::cpp_source(code = "
ignore_sigpipes()
# Initialize a dictionary of file paths. See misc/file_dict.csv for details
paths <- model_file_dict(params$run_id, params$year)
paths <- model_file_dict(model_params$run_id, model_params$year)
# Grab metadata to check input alignment
metadata <- read_parquet(paths$output$metadata$local)
Expand Down Expand Up @@ -98,7 +79,6 @@ if (file.exists(paths$output$shap$local)) {
feat_imp_df <- read_parquet(paths$output$feature_importance$local)
```


```{r}
# This script runs balance tests comparing the universe of residential parcels
# to the sample of residential parcels with sales in the previous 8 years
Expand Down

0 comments on commit 4bcb8ae

Please sign in to comment.