Skip to content

Commit

Permalink
Deprecate pvec and remove useless dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
clente committed Jul 2, 2019
1 parent 0e3d3c8 commit 940628f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 37 deletions.
34 changes: 7 additions & 27 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,10 @@ Title: Useful Tools for Jurimetrical Analysis Used by the
Version: 0.2.3
Date: 2019-02-04
Authors@R:
c(person(given = "Julio",
family = "Trecenti",
role = "aut",
email = "[email protected]"),
person(given = "Athos",
family = "Damiani",
role = "ctb",
email = "[email protected]"),
person(given = "Fernando",
family = "Correa",
role = "aut",
email = "[email protected]"),
person(given = "Caio",
family = "Lente",
role = c("aut", "cre"),
email = "[email protected]"),
person(family = "Brazilian Jurimetrics Association",
role = "cph"))
person(
family = "ABJ",
email = "[email protected]",
role = c("aut", "cre", "cph"))
Maintainer: Caio Lente <[email protected]>
Description: The Brazilian Jurimetrics Association (ABJ in
Portuguese, see <http://www.abjur.org.br/en/> for more information) is
Expand All @@ -37,24 +23,18 @@ URL: https://github.com/abjur/abjutils
Depends:
R (>= 3.4)
Imports:
devtools,
dplyr,
furrr,
future,
glue,
httr,
magrittr,
progress,
purrr,
readr,
rlang,
rstudioapi,
scales,
stringi,
stringr,
tibble,
tidyr
Suggests:
devtools,
furrr,
future,
testthat
LazyData: TRUE
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace",
Expand Down
2 changes: 1 addition & 1 deletion R/cnj.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ separate_cnj <- function(data, col, ...) {
#'
#' @export
pattern_cnj <- function() {
glue::glue(
stringr::str_glue(
"[0-9]{{3,7}}-?",
"[0-9]{{2}}\\.?",
"[0-9]{{4}}\\.?",
Expand Down
2 changes: 0 additions & 2 deletions R/esaj.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ gather_subjects <- function(subjects) {
unite_index <- function(d, i) {
tidyr::unite_(d, paste0("level", i), paste0(c("id", "name"), i))
}
col <- readr::cols(.default = readr::col_character())
purrr::reduce(0:5, unite_index, .init = subjects) %>%
tidyr::gather() %>%
tidyr::separate(value, c("id", "nm"), sep = "_") %>%
dplyr::distinct(id, .keep_all = TRUE) %>%
readr::type_convert(col_types = col) %>%
dplyr::filter(!is.na(id))
}
4 changes: 3 additions & 1 deletion R/pvec.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#' @return A tibble with 3 columns: input, return, and output
#' @export
pvec <- function(.x, .f, ..., .cores = get_cores(), .progress = TRUE, .flatten = FALSE, .options = future_options()) {

.Deprecated("furrr::future_map")

# Preserve execution plan
oplan <- future::plan()
Expand Down Expand Up @@ -54,7 +56,7 @@ pvec <- function(.x, .f, ..., .cores = get_cores(), .progress = TRUE, .flatten =
pout <- out %>%
purrr::map(compact_) %>%
purrr::flatten() %>%
tibble::tibble(
dplyr::tibble(
id = purrr::`%||%`(names(.x), seq_along(.x)),
return = names(.), output = .
)
Expand Down
4 changes: 2 additions & 2 deletions R/table_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ prettify_number <- function(d, number = T, percent = T, ...) {
}

if (number) {
query <- sprintf("{fmt(x)} (%s)", glue::glue(query))
query <- sprintf("{fmt(x)} (%s)", stringr::str_glue(query))
}

d %>%
dplyr::select(...) %>%
dplyr::mutate_if(is.numeric, .funs = function(x) {
glue::glue(query)
stringr::str_glue(query)
}) %>%
dplyr::as_data_frame()
}
Expand Down
20 changes: 19 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ use_pipe <- function(pkg = ".") {
#' @export
precision <- function(x) {
rng <- range(x, na.rm = TRUE)
span <- if (scales::zero_range(rng)) {
span <- if (zero_range(rng)) {
abs(rng[1])
} else {
diff(rng)
Expand All @@ -142,6 +142,24 @@ precision <- function(x) {
10^floor(log10(span))
}

# Mirror of scales::zero_range
zero_range <- function (x, tol = 1000 * .Machine$double.eps) {
if (length(x) == 1)
return(TRUE)
if (length(x) != 2)
stop("x must be length 1 or 2")
if (any(is.na(x)))
return(NA)
if (x[1] == x[2])
return(TRUE)
if (all(is.infinite(x)))
return(FALSE)
m <- min(abs(x))
if (m == 0)
return(FALSE)
abs((x[1] - x[2])/m) < tol
}

#' Convert brazilian currency values (text) to numeric
#'
#' @param x A currency vector. Ex: c("R$ 10.000,00", "R$ 123,00")
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ devtools::install_github("abjur/abjutils")

## Usage

`abjutils` has many functions, but the most useful are listed below
`abjutils` has many functions, but for regular users the most useful ones are
listed below

- `rm_accent`: removes diacritics from a string

- `escape_unicode`: replaces accented characters by their unicode-escaped values
(also an add-in)

- `pvec`: a safe and protected vectorizer useful for things such as web scrapers

## Citations

To cite this package, use `citation("abjutils")`:
Expand Down

0 comments on commit 940628f

Please sign in to comment.