Skip to content

Commit

Permalink
Merge pull request #82 from jrdnbradford/polish-force-param
Browse files Browse the repository at this point in the history
Finish up `force` and `warn`
  • Loading branch information
jrdnbradford authored Jan 3, 2025
2 parents b5df21d + d46e0ab commit ab9e894
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# readMDTable (development version)

* BREAKING CHANGE: `force` param added for `read_md_table` (#74)
* Fixed a typo in a warning message (#59)
* `extract_md_table` alias added for `extract_md_tables` (#69)
* Improvements to markdown table matching (#76)
* `force` param added for `read_md_table` (#74)
* Warnings now rely entirely on matching main regex (#69)

# readMDTable 0.2.0
Expand Down
17 changes: 13 additions & 4 deletions R/read_md_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,29 @@ read_md_table <- function(file, warn = TRUE, force = FALSE, ...) {
if (warn) {
cli::cli_warn(
c(
"x" = "Content in provided `file` does not match the readMDTable regex",
"i" = "File an issue at https://github.com/jrdnbradford/readMDTable/issues if this warning is in error"
"x" = "Content in provided `file` does not match the readMDTable regex.",
"i" = "File an issue at https://github.com/jrdnbradford/readMDTable/issues if this warning is in error."
)
)
}
if (force) {
if (warn) {
cli::cli_alert_info(
cli::cli_warn(
c(
"i" = "Attempting to read in content anyway"
"i" = "Attempting to read in content does not match the readMDTable regex."
)
)
}
return(read_md_table_content(content, ...))
} else {
if (warn) {
cli::cli_warn(
c(
"i" = "Cannot read content. Set `force = TRUE` to attempt reading anyway. This may return unexpected results."
)
)
}
return(NULL)
}
}
return(read_md_table_content(table, ...))
Expand Down
25 changes: 7 additions & 18 deletions tests/testthat/_snaps/read_md_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,19 @@
md <- read_md_table(md_file, force = TRUE, show_col_types = FALSE)
Condition
Warning:
x Content in provided `file` does not match the readMDTable regex
i File an issue at https://github.com/jrdnbradford/readMDTable/issues if this warning is in error
Message
i Attempting to read in content anyway
x Content in provided `file` does not match the readMDTable regex.
i File an issue at https://github.com/jrdnbradford/readMDTable/issues if this warning is in error.
Warning:
i Attempting to read in content does not match the readMDTable regex.

# read_md_table handles separator line format of Gutenberg Project's mirror table

Code
md <- read_md_table(md_file, force = TRUE, show_col_types = FALSE)
Condition
Warning:
x Content in provided `file` does not match the readMDTable regex
i File an issue at https://github.com/jrdnbradford/readMDTable/issues if this warning is in error
Message
i Attempting to read in content anyway

# read_md_table handles file with no tables

Code
md <- read_md_table(md_file, force = TRUE, show_col_types = FALSE)
Condition
x Content in provided `file` does not match the readMDTable regex.
i File an issue at https://github.com/jrdnbradford/readMDTable/issues if this warning is in error.
Warning:
x Content in provided `file` does not match the readMDTable regex
i File an issue at https://github.com/jrdnbradford/readMDTable/issues if this warning is in error
Message
i Attempting to read in content anyway
i Attempting to read in content does not match the readMDTable regex.

9 changes: 4 additions & 5 deletions tests/testthat/test-read_md_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ test_that("read_md_table handles alignment separators", {
test_that("read_md_table handles file with no tables", {
md_file <- test_path("testmd", "no-table.md")
expect_warning(
expect_error(
md <- read_md_table(md_file, show_col_types = FALSE)
expect_warning(
read_md_table(md_file, force = FALSE, show_col_types = FALSE)
)
)

expect_snapshot(
md <- read_md_table(md_file, force = TRUE, show_col_types = FALSE)
expect_null(
read_md_table(md_file, force = FALSE, warn = FALSE, show_col_types = FALSE)
)
})

0 comments on commit ab9e894

Please sign in to comment.