Skip to content

Commit

Permalink
fix-empty-match
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolepore committed Mar 9, 2024
1 parent cfa95eb commit 845bb65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions R/map_chunks.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ map_chunks <- function(data,
.by,
chunks,
cache_dir,
order = "identity") {
order = "identity",
options = NULL) {
parent <- rm_namespace(deparse(substitute(.f)))
job <- data |>
nest_chunk(.by = .by, chunks = chunks) |>
add_file(cache_path(parent, cache_dir = dir_create(cache_dir)))

op <- extract_options("tiltIndicatorAfter")

job |>
pick_undone() |>
dchunkr::order_rows(.fun = order) |>
select("data", "file") |>
future_pwalk(
function(data, file) {
# Pass options https://github.com/HenrikBengtsson/future/issues/134
withr::local_options(op)
withr::local_options(options)
.f(data, ...) |>
write_rds(file)
},
Expand All @@ -34,5 +33,9 @@ rm_namespace <- function(x) {
}

extract_options <- function(pattern) {
options()[grep(pattern, names(options()), value = TRUE)]
out <- options()[grep(pattern, names(options()), value = TRUE)]
if (identical(length(out), 0L)) {
out <- options()
}
out
}
4 changes: 4 additions & 0 deletions R/profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ profile_emissions <- function(companies,
chunks = handle_chunks(companies),
cache_dir = cache_dir,
order = order,
options = extract_options("tiltIndicatorAfter"),
.by = "companies_id",
.f = tiltIndicatorAfter::profile_emissions,
co2 = co2,
Expand Down Expand Up @@ -98,6 +99,7 @@ profile_emissions_upstream <- function(companies,
chunks = handle_chunks(companies),
cache_dir = cache_dir,
order = order,
options = extract_options("tiltIndicatorAfter"),
.f = tiltIndicatorAfter::profile_emissions_upstream,
co2 = co2,
europages_companies = europages_companies,
Expand Down Expand Up @@ -154,6 +156,7 @@ profile_sector <- function(companies,
chunks = handle_chunks(companies),
cache_dir = cache_dir,
order = order,
options = extract_options("tiltIndicatorAfter"),
.f = tiltIndicatorAfter::profile_sector,
scenarios = scenarios,
europages_companies = europages_companies,
Expand Down Expand Up @@ -213,6 +216,7 @@ profile_sector_upstream <- function(companies,
chunks = handle_chunks(companies),
cache_dir = cache_dir,
order = order,
options = extract_options("tiltIndicatorAfter"),
.f = tiltIndicatorAfter::profile_sector_upstream,
scenarios = scenarios,
inputs = inputs,
Expand Down

0 comments on commit 845bb65

Please sign in to comment.