From c2ec8010cd5c5100ab3b19b7e4c1fd25e1d4115a Mon Sep 17 00:00:00 2001 From: Dominic Schuhmacher Date: Wed, 29 May 2024 15:41:05 +0200 Subject: [PATCH] Fix problems in winbuilder check due to non-availability of kanjistat.data --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/stroke_edit_distance.R | 1 + tests/testthat/test-stroke_edit_distance.R | 31 ++++++++++++---------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 40107cc..d3d3c50 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -43,7 +43,7 @@ Suggests: testthat (>= 3.0.0), tibble, withr -Remotes: dschuhmacher/kanjistat.data +Additional_repositories: https://dschuhmacher.github.io/drat License: GPL (>= 3) Encoding: UTF-8 LazyData: true diff --git a/NEWS.md b/NEWS.md index 66839e0..ece6bc9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# kanjistat 0.13.2.9100 (development version) +# kanjistat 0.14.0 (2024-05-29) ## New features diff --git a/R/stroke_edit_distance.R b/R/stroke_edit_distance.R index e16aa21..c21a8ec 100644 --- a/R/stroke_edit_distance.R +++ b/R/stroke_edit_distance.R @@ -130,6 +130,7 @@ strokesignature2 <- function(kvec) { #' } #' sedist <- function(k1, k2, type = c("full", "before_slash", "first")) { + check_for_data() type <- match.arg(type) kvec1 <- convert_kanji(k1, "kanjivec", simplify=FALSE) if (is(kvec1, "kanjivec")) { # if k1 was just a single kanji specified in atomic form diff --git a/tests/testthat/test-stroke_edit_distance.R b/tests/testthat/test-stroke_edit_distance.R index 4d2b3ab..2482f92 100644 --- a/tests/testthat/test-stroke_edit_distance.R +++ b/tests/testthat/test-stroke_edit_distance.R @@ -1,17 +1,18 @@ # contains indirectly also tests for values of dstrokedit test_that("sedist, same as Yencken, type does not matter", { - ind1 <- 384L - ind2 <- c(93L, 413L, 786L, 895L, 1020L, 1137L, 1282L, 1359L, 1433L, 1642L, 1959L) - res <- sedist(ind1, ind2) - expect_equal(res, matrix(dstrokedit[ind1,ind2], 1, length(ind2)), tolerance = 1e-6) - expected <- structure(c(0.25, 0.25, 0.33333333333333331, 0.30769230769230771, - 0.30769230769230771, 0.41666666666666669, 0.41666666666666669, - 0.25, 0.41666666666666669, 0.41666666666666669, 0.41666666666666669 - ), dim = c(1L, 11L)) - expect_equal(res, expected) - expect_equal(sedist(ind1, ind2, type="before_slash"), expected) - expect_equal(sedist(ind1, ind2, type="first"), expected) + skip_if_not_installed("spatstat.data") + ind1 <- 384L + ind2 <- c(93L, 413L, 786L, 895L, 1020L, 1137L, 1282L, 1359L, 1433L, 1642L, 1959L) + res <- sedist(ind1, ind2) + expect_equal(res, matrix(dstrokedit[ind1,ind2], 1, length(ind2)), tolerance = 1e-6) + expected <- structure(c(0.25, 0.25, 0.33333333333333331, 0.30769230769230771, + 0.30769230769230771, 0.41666666666666669, 0.41666666666666669, + 0.25, 0.41666666666666669, 0.41666666666666669, 0.41666666666666669 + ), dim = c(1L, 11L)) + expect_equal(res, expected) + expect_equal(sedist(ind1, ind2, type="before_slash"), expected) + expect_equal(sedist(ind1, ind2, type="first"), expected) }) @@ -28,9 +29,11 @@ test_that("sedist, different from Yencken, type does matter", { 0.33333333333333331, 0.33333333333333331, 0.2857142857142857, 0.5, 0.44444444444444442) # sedist first expect_equal(dstrokedit[ind1,ind2], expected0) - expect_equal( as.vector(sedist(ind1, ind2, type="full")), expected1) - expect_equal( as.vector(sedist(ind1, ind2, type="before_slash")), expected1) - expect_equal( as.vector(sedist(ind1, ind2, type="first")), expected2) + # + skip_if_not_installed("spatstat.data") + expect_equal( as.vector(sedist(ind1, ind2, type="full")), expected1) + expect_equal( as.vector(sedist(ind1, ind2, type="before_slash")), expected1) + expect_equal( as.vector(sedist(ind1, ind2, type="first")), expected2) }) # first entry checked manually using strokesigraw and historical stroke type data by Lars Yencken # 観 4,2,3,4,3,4,2b,3a,2b,2b,2b,3,11a,2a,2a,2a,4,19 (500)