Skip to content

Commit

Permalink
Setup lintr and fix a few lints (#112)
Browse files Browse the repository at this point in the history
* Setup `lintr` and fix a few lints

* fix merge conflicts

* put .lintr in buildignore

---------

Co-authored-by: Beniamino Green <[email protected]>
  • Loading branch information
etiennebacher and beniaminogreen authored Feb 14, 2024
1 parent 8131984 commit 090a56d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ src/rust/uncomment.sh
^CRAN-SUBMISSION$
^.*\.Rproj$
^\.Rproj\.user$
.lintr
7 changes: 7 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
linters: linters_with_defaults(
line_length_linter = NULL,
indentation_linter = NULL,
commas_linter = NULL,
infix_spaces_linter = NULL
) # see vignette("lintr")
encoding: "UTF-8"
2 changes: 1 addition & 1 deletion R/em_link.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#' @export
em_link <- function(X, g, tol = 10^-6, max_iter = 10^3) {
stopifnot(
"There can be no NA's in X (but you can add NA as its own agreement level)" = !any(is.na(X))
"There can be no NA's in X (but you can add NA as its own agreement level)" = !anyNA(X)
)

stopifnot(
Expand Down
9 changes: 4 additions & 5 deletions R/euclidean_join_core.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ multi_by_validate <- function(a, b, by) {
by_a <- by
by_b <- by
}

stopifnot(by_a %in% names(a))
stopifnot(by_b %in% names(b))
}
Expand All @@ -37,10 +36,10 @@ euclidean_join_core <- function(a, b, by = NULL, n_bands = 30, band_width = 10,
by <- multi_by_validate(a, b, by)
by_a <- by[[1]]
by_b <- by[[2]]
stopifnot("There should be no NA's in by_a[1]" = !any(is.na(dplyr::pull(a, by_a[1]))))
stopifnot("There should be no NA's in by_a[2]" = !any(is.na(dplyr::pull(a, by_a[2]))))
stopifnot("There should be no NA's in by_b[1]" = !any(is.na(dplyr::pull(b, by_b[1]))))
stopifnot("There should be no NA's in by_b[2]" = !any(is.na(dplyr::pull(b, by_b[2]))))
stopifnot("There should be no NA's in by_a[1]" = !anyNA(a[[by_a[1]]]))
stopifnot("There should be no NA's in by_a[2]" = !anyNA(a[[by_a[2]]]))
stopifnot("There should be no NA's in by_b[1]" = !anyNA(b[[by_b[1]]]))
stopifnot("There should be no NA's in by_b[2]" = !anyNA(b[[by_b[2]]]))

thresh_prob <- euclidean_probability(threshold, n_bands, band_width, r)
if (thresh_prob < .95) {
Expand Down
11 changes: 4 additions & 7 deletions R/jaccard_join_core.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,17 @@ jaccard_join <- function(a, b, mode, by, salt_by, n_gram_width, n_bands,
") have only a ", round(thresh_prob * 100), "% chance of being compared.\n",
"Please consider changing `n_bands` and `band_width`."
)

warning(str)
}



by <- simple_by_validate(a, b, by)
by_a <- by[[1]]
by_b <- by[[2]]
stopifnot("'by' vectors must have length 1" = length(by_a) == 1)
stopifnot("'by' vectors must have length 1" = length(by_b) == 1)

stopifnot("There should be no NA's in by_a" = !any(is.na(dplyr::pull(a, by_a))))
stopifnot("There should be no NA's in by_b" = !any(is.na(dplyr::pull(b, by_b))))
stopifnot("There should be no NA's in by_a" = !anyNA(a[[by_a]]))
stopifnot("There should be no NA's in by_b" = !anyNA(b[[by_b]]))

salt_by_a <- NULL
salt_by_b <- NULL
Expand All @@ -82,9 +79,9 @@ jaccard_join <- function(a, b, mode, by, salt_by, n_gram_width, n_bands,
salt_by_a <- salt_by[[1]]
salt_by_b <- salt_by[[2]]
stopifnot("There should be no NA's in the blocking variables" = !
any(is.na(dplyr::select(a, dplyr::all_of(salt_by_a)))))
anyNA(a[, salt_by_a, drop = FALSE]))
stopifnot("There should be no NA's in the blocking variables" = !
any(is.na(dplyr::select(b, dplyr::all_of(salt_by_b)))))
anyNA(b[, salt_by_b, drop = FALSE]))
}

# Clean strings that are matched on
Expand Down

0 comments on commit 090a56d

Please sign in to comment.