Skip to content

Commit

Permalink
Stop resolution multiplying rows from metadata (Fixes #379)
Browse files Browse the repository at this point in the history
The metadata column was causing certain rows to recycle  over the
result data frame. The solution here is to check if the list is
not already length one and to wrap it into a list if it is not.

Also added an assertion to force the output into being one row
as desired.
  • Loading branch information
jameslairdsmith committed Sep 5, 2024
1 parent 2755f46 commit fea559a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion R/resolution-df.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ res_one_row_df <- function(l) {
assert_that(is.list(l) && all_named(l))
samp <- res_make_empty_df()[names(l)]
bad <- vlapply(samp, is.list) & !vlapply(l, is.list)
# If col is isn't a list col, but is supposed to be.
bad_len <- vlapply(samp, is.list) & !vlapply(l, function(x) length(x) == 1)
# If col is supposed to be a list, but isn't length one.
bad <- bad | bad_len
l[bad] <- lapply(l[bad], list)
as_data_frame(l)
out <- as_data_frame(l)
assert_that(nrow(out) == 1)
out
}

res_list_to_df <- function(reslist) {
Expand Down

0 comments on commit fea559a

Please sign in to comment.