Skip to content

Commit

Permalink
pass through readr's problems attribute (#83)
Browse files Browse the repository at this point in the history
closes #35

Co-authored-by: CJ Yetman - RMI <cjrmi@CJs-MacBook-Pro.fritz.box>
  • Loading branch information
cjyetman and CJ Yetman - RMI authored Mar 13, 2024
1 parent 4d340af commit 5028df1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/read_portfolio_csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ read_portfolio_csv <- function(filepaths, combine = TRUE) {
show_col_types = FALSE,
progress = FALSE
)
problems_attr <- attr(portfolio_df, "problems")

portfolio_df <-
dplyr::select(
Expand Down Expand Up @@ -130,6 +131,7 @@ read_portfolio_csv <- function(filepaths, combine = TRUE) {
grouping_mark = grouping_mark
)
attr(portfolio_df, which = "read_portfolio_csv") <- guessed_attrs
attr(portfolio_df, which = "problems") <- problems_attr

list(portfolio_df)
},
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-read_portfolio_csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,16 @@ test_that("reads and combines multiple portfolio CSVs correctly into a list when
expect_equal(result[[1L]], portfolio_min, ignore_attr = TRUE)
expect_equal(result[[2L]], NA)
})

test_that("passes readr problems attribute through correctly", {
csv_file <- withr::local_tempfile(fileext = ".csv")

portfolio_alt <- portfolio_min
portfolio_alt$market_value <- "X"

readr::write_csv(portfolio_alt, file = csv_file)

expect_warning({ result <- read_portfolio_csv(csv_file) })
expect_true(!is.null(attr(result, "problems")))
expect_gt(nrow(readr::problems(result)), 0L)
})

0 comments on commit 5028df1

Please sign in to comment.