diff --git a/R/paistr.R b/R/paistr.R index 7480fba..d18e412 100644 --- a/R/paistr.R +++ b/R/paistr.R @@ -127,8 +127,13 @@ generics::tidy #' @export tidy.skksph_paistr <- function(x, ...) { n_tiles <- vctrs::vec_data(x) |> - stringi::stri_replace_all_fixed(",", "") |> # treat any fulou as bingpai - skksph_tidy_impl() + purrr::map(~ { + stringi::stri_replace_all_regex(.x, "[\\-\\=\\+]", "") |> + stringi::stri_split_fixed(",") |> + unlist(use.names = FALSE) |> + skksph_tidy_impl() |> + purrr::reduce(`+`) + }) df <- data.frame( id = rep(seq_along(n_tiles), each = 38), diff --git a/tests/testthat/_snaps/paistr.md b/tests/testthat/_snaps/paistr.md index f287b20..ff2dec0 100644 --- a/tests/testthat/_snaps/paistr.md +++ b/tests/testthat/_snaps/paistr.md @@ -28,7 +28,7 @@ { "type": "integer", "attributes": {}, - "value": [0] + "value": [1] }, { "type": "integer", @@ -39,7 +39,7 @@ "value": [1, 34] } }, - "value": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1] + "value": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0] } ] } @@ -85,7 +85,7 @@ "value": ["factor"] } }, - "value": [11, 13, 14, 15, 16, 32, 33, 34, 35, 36, 37] + "value": [11, 13, 14, 15, 16, 22, 23, 24, 32, 33, 34] }, { "type": "integer", diff --git a/tests/testthat/test-paistr.R b/tests/testthat/test-paistr.R index 5c60542..eed5fde 100644 --- a/tests/testthat/test-paistr.R +++ b/tests/testthat/test-paistr.R @@ -12,11 +12,11 @@ test_that("paistr works", { }) test_that("calculate for paistr works", { - pai <- paistr("p0222345z234567") + pai <- paistr("p0222345z234,s1-23") expect_snapshot_value(calculate(pai), style = "json2", cran = FALSE) }) test_that("tidy for paistr works", { - pai <- paistr("p0222345z234567") + pai <- paistr("p0222345z234,s1-23") expect_snapshot_value(tidy(pai), style = "json2", cran = FALSE) })