Skip to content

Commit

Permalink
fix(app): #27 Enable archive export
Browse files Browse the repository at this point in the history
re-enable zip output and csv conversion.

Note: if a JSON file is does not read as a data.frame (empty array,
`[]`), then this will not emit a corresponding csv file, but will add
the empty JSON to the archive (for later diagnostic purposes).

Closes: #27
  • Loading branch information
AlexAxthelm committed Dec 10, 2024
1 parent 0d72134 commit f181306
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions R/prepare_pacta_dashboard_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ prep_key_bars_portfolio(

# put JSON and CSV outputs into a zip archive ----------------------------------

# zip_outputs(output_dir)
zip_outputs(output_dir)

Check warning on line 346 in R/prepare_pacta_dashboard_data.R

View check run for this annotation

Codecov / codecov/patch

R/prepare_pacta_dashboard_data.R#L346

Added line #L346 was not covered by tests

}

Expand All @@ -362,15 +362,19 @@ zip_outputs <- function(output_dir) {

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

jsonlite::read_json(
df <- jsonlite::read_json(

Check warning on line 365 in R/prepare_pacta_dashboard_data.R

View check run for this annotation

Codecov / codecov/patch

R/prepare_pacta_dashboard_data.R#L365

Added line #L365 was not covered by tests
path = file.path(output_dir, json_filename),
simplifyVector = TRUE
) %>%
)

Check warning on line 368 in R/prepare_pacta_dashboard_data.R

View check run for this annotation

Codecov / codecov/patch

R/prepare_pacta_dashboard_data.R#L368

Added line #L368 was not covered by tests

if (inherits(df, "data.frame")) {

Check warning on line 370 in R/prepare_pacta_dashboard_data.R

View check run for this annotation

Codecov / codecov/patch

R/prepare_pacta_dashboard_data.R#L370

Added line #L370 was not covered by tests
readr::write_csv(
x = df,

Check warning on line 372 in R/prepare_pacta_dashboard_data.R

View check run for this annotation

Codecov / codecov/patch

R/prepare_pacta_dashboard_data.R#L372

Added line #L372 was not covered by tests
file = file.path(zip_temp, csv_filename),
na = "",
eol = "\n"
)
}
}

utils::zip(
Expand Down

0 comments on commit f181306

Please sign in to comment.