Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
Fix #46
Browse files Browse the repository at this point in the history
  • Loading branch information
chainsawriot committed Nov 22, 2023
1 parent 5f08a69 commit cf1acd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/get_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@ dfm.tokens_with_proximity <- function(x, tolower = TRUE, remove_padding = FALSE,
x_attrs <- attributes(x)
x_docvars <- quanteda::docvars(x)
x_docnames <- attr(x, "docvars")$docname_
type <- attr(x, "types")
temp <- unclass(x)
index <- unlist(temp, use.names = FALSE)
type <- attr(x, "types")
if (0 %in% index) {
index <- index + 1
type <- c("", type)
}
val <- weight_function(unlist(quanteda::docvars(x, "proximity"), use.names = FALSE))
temp <- Matrix::sparseMatrix(
j = index,
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-dfm.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ test_that("tolower", {
res %>% dfm(tolower = TRUE) -> output
expect_true("turkish" %in% colnames(output))
})

test_that("Padding #46", {
suppressPackageStartupMessages(library(quanteda))
toks <- tokens(c("a b c", "A B C D")) %>% tokens_remove("b", padding = TRUE)
expect_error(toks %>% tokens_proximity("a") %>% dfm(), NA)
})

0 comments on commit cf1acd9

Please sign in to comment.