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

Commit

Permalink
remove purrr ref #28 (#29)
Browse files Browse the repository at this point in the history
* removed purr from convert

* removed purrr in get_proximity
  • Loading branch information
schochastics authored Nov 17, 2023
1 parent 71dcd47 commit 248b329
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions R/get_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ row_mins_c <- function(mat) {

get_proximity <- function(x, keywords, get_min = TRUE, count_from = 1) {
keywords_poss <- which(attr(x, "types") %in% keywords)
purrr::map(x, .get_proximity, keywords_poss = keywords_poss, get_min = get_min, count_from = count_from)
lapply(unclass(x), .get_proximity, keywords_poss = keywords_poss, get_min = get_min, count_from = count_from)
}

.resolve_keywords <- function(keywords, features, valuetype) {
Expand Down Expand Up @@ -113,16 +113,14 @@ print.tokens_with_proximity <- function(x, ...) {
#' @importFrom quanteda convert
convert.tokens_with_proximity <- function(x, to = c("data.frame"), ...) {
to <- match.arg(to)
purrr::list_rbind(
purrr::pmap(
list(
tokens_obj = as.list(x),
proximity_obj = quanteda::docvars(x, "proximity"),
doc_id = quanteda::docnames(x)
),
.convert_df
)
result_list <- mapply(
FUN = .convert_df,
tokens_obj = as.list(x),
proximity_obj = quanteda::docvars(x, "proximity"),
doc_id = quanteda::docnames(x),
SIMPLIFY = FALSE
)
do.call(rbind, result_list)
}

#' Create a document-feature matrix
Expand Down

0 comments on commit 248b329

Please sign in to comment.