Skip to content

Commit

Permalink
output a ZIP with JSON and CSV versions of all outputs (#36)
Browse files Browse the repository at this point in the history
* output a ZIP with JSON and CSV versions of all outputs

* Update prepare_pacta_dashboard_data.R

* Update DESCRIPTION

* Update prepare_pacta_dashboard_data.R

---------

Co-authored-by: Jackson Hoffart <[email protected]>
  • Loading branch information
cjyetman and jdhoffa authored Dec 5, 2024
1 parent adebb07 commit 750d539
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: workflow.pacta.dashboard
Title: Run PACTA dashboard JSON generation
Version: 0.0.0.9003
Version: 0.0.0.9004
Authors@R:
c(person(given = "Alex",
family = "Axthelm",
Expand Down
37 changes: 37 additions & 0 deletions R/prepare_pacta_dashboard_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,41 @@ prep_key_bars_portfolio(
translate_df_contents("data_key_bars_portfolio", dictionary) %>%
jsonlite::write_json(path = file.path(output_dir, "data_techexposure_company_portfolio.json"))


# put JSON and CSV outputs into a zip archive ----------------------------------
zip_outputs(output_dir)

}


zip_outputs <- function(output_dir) {
json_filenames <- list.files(output_dir, pattern = "[.]json$")

zip_temp <- file.path(tempdir(), "zip_temp")
dir.create(zip_temp, showWarnings = FALSE)

for (json_filename in json_filenames) {
file.copy(
from = file.path(output_dir, json_filename),
to = file.path(zip_temp, json_filename)
)

csv_filename <- sub("[.]json$", ".csv", json_filename)

jsonlite::read_json(
path = file.path(output_dir, json_filename),
simplifyVector = TRUE
) %>%
readr::write_csv(
file = file.path(zip_temp, csv_filename),
na = "",
eol = "\n"
)
}

utils::zip(
zipfile = file.path(output_dir, "archive.zip"),
files = list.files(zip_temp, full.names = TRUE),
flags = "-r9Xjq"
)
}

0 comments on commit 750d539

Please sign in to comment.