Skip to content

Commit

Permalink
Styling
Browse files Browse the repository at this point in the history
  • Loading branch information
clente committed Feb 4, 2019
1 parent 0540704 commit a1fa097
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 250 deletions.
94 changes: 56 additions & 38 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,44 +1,62 @@
Package: abjutils
Type: Package
Date: 2018-01-18
Title: Useful Tools for Jurimetrical Analysis Used by the Brazilian Jurimetrics Association
Description: The Brazilian Jurimetrics Association (ABJ in Portuguese,
see <http://www.abjur.org.br/en/> for more information) is a non-profit
organization which aims to investigate and promote the use of
statistics and probability in the study of Law and its institutions.
This package implements general purpose tools used by ABJ, such as functions
for sampling and basic manipulation of Brazilian lawsuits identification
number. It also implements functions for text cleaning, such as accentuation removal.
Package: abjutils
Title: Useful Tools for Jurimetrical Analysis Used by the
Brazilian Jurimetrics Association
Version: 0.2.3
Authors@R: c(
person("Julio", "Trecenti", role = "aut", email = "[email protected]"),
person("Athos", "Damiani", role = "ctb", email = "[email protected]"),
person("Fernando", "Correa", role = "aut", email = "[email protected]"),
person("Caio", "Lente", role = c("aut","cre"), email = "[email protected]"),
person(family = "Brazilian Jurimetrics Association", role = "cph"))
Date: 2018-01-18
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"))
Maintainer: Caio Lente <[email protected]>
URL: https://github.com/abjur/abjutils
LazyData: TRUE
Depends: R (>= 3.4)
Description: The Brazilian Jurimetrics Association (ABJ in
Portuguese, see <http://www.abjur.org.br/en/> for more information) is
a non-profit organization which aims to investigate and promote the
use of statistics and probability in the study of Law and its
institutions. This package implements general purpose tools used by
ABJ, such as functions for sampling and basic manipulation of
Brazilian lawsuits identification number. It also implements functions
for text cleaning, such as accentuation removal.
License: MIT + file LICENSE
URL: https://github.com/abjur/abjutils
Depends:
R (>= 3.4)
Imports:
stringr,
dplyr,
httr,
tibble,
devtools,
magrittr,
purrr,
rstudioapi,
scales,
stringi,
glue,
tidyr,
progress,
furrr,
future,
readr,
rlang
Suggests: testthat
devtools,
dplyr,
furrr,
future,
glue,
httr,
magrittr,
progress,
purrr,
readr,
rlang,
rstudioapi,
scales,
stringi,
stringr,
tibble,
tidyr
Suggests:
testthat
LazyData: TRUE
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace",
"collate"))
RoxygenNote: 6.1.1
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate"))
4 changes: 1 addition & 3 deletions R/carf.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ verify_length <- function(val) {
#' carf_calc_dig("10120.008427/2003", build = TRUE)
#' carf_calc_dig("15374.002430/99", build = FALSE)
#' carf_calc_dig(c("101200084272003", "1537400243099"))
#'
#' # will fail
#' \donttest{
#' carf_calc_dig("10766.000511/96-12")
#' }
Expand Down Expand Up @@ -95,4 +93,4 @@ carf_build_id <- function(id) {
} else {
stop ("Length must be 15 or 17.")
}
}
}
4 changes: 1 addition & 3 deletions R/cnj.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#' @title Calculate digits for Brazilian lawsuit identification numbers
#'
#' @description Returns the check digit of a lawsuit numbers in the format
Expand All @@ -13,8 +14,6 @@
#' @examples {
#' calc_dig("001040620018260004", build = TRUE)
#' calc_dig("001040620018260004", build = FALSE)
#'
#' #will fail
#' \dontrun{
#' calc_dig("00104062001826000", build = TRUE)
#' }
Expand Down Expand Up @@ -253,4 +252,3 @@ pattern_cnj <- function() {
clean_cnj <- function(x) {
stringr::str_replace_all(x, '[^0-9]','')
}

16 changes: 8 additions & 8 deletions R/esaj.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

#' @title Gather subjects from esaj::cjsg_table("subjects")
#'
#'
#' @description Once you run `esaj::cjsg_table("subjects")`, you can
#' use this function to gather the subjects automatically. Download
#' `esaj` by running `devtools::install_github("courtsbr/esaj")`.
#'
#'
#' @param subjects Table returned by `esaj::cjsg_table("subjects")`
#'
#'
#' @export
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) %>%
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))
}
10 changes: 5 additions & 5 deletions R/escape_unicode.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@

#' @title Escape accented characters in a document
#'
#'
#' @description This function is used by the "Escape Unicode" add-in
#' and removes all accented characters from the current file, replacing
#' them by their equivalent Unicode-escaped values.
#'
#'
#' @export
escape_unicode <- function() {

# Escape accented characters from one character vector
escape <- . %>%
stringi::stri_escape_unicode() %>%
stringi::stri_replace_all_fixed("\\\\", "#$!*%") %>%
stringi::stri_replace_all_fixed("\\", "") %>%
stringi::stri_replace_all_fixed("#$!*%", "\\") %>%
stringr::str_replace_all("(u00[:alnum:]{2})", "\\\\\\1")

# Escape accented characters from every line of the document
escape_all <- . %>%
purrr::map_chr(escape) %>%
stringr::str_c(collapse = "\n")

# Get text of document and escape accented characters
doc <- rstudioapi::getSourceEditorContext()

Expand Down
34 changes: 18 additions & 16 deletions R/pvec.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
#' and the returned object is flattened (a vector, a list, or a tibble)
#' @param .options Options passed on to [furrr::future_map()]
#' ([furrr::future_options()] by default)
#'
#'
#' @seealso [purrr::map()], [furrr::future_map()], [furrr::future_options()]
#'
#'
#' @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()) {

# Preserve execution plan
oplan <- future::plan()
on.exit(future::plan(oplan), add = TRUE)

# Set execution plan to multicore
future::plan(future::multicore, workers = .cores)

# Capture function side-effects
.f <- purrr::safely(purrr::as_mapper(.f))

# Run future map
out <- furrr::future_map(.x, .f, ..., .progress = .progress, .options = .options)

# Compact with care
compact_ <- function(x) {
if (is.null(x[[1]]) && is.null(x[[2]])) {
Expand All @@ -46,35 +46,37 @@ pvec <- function(.x, .f, ..., .cores = get_cores(), .progress = TRUE, .flatten =
return(purrr::compact(x))
}
}

# Process output
pout <- out %>%
purrr::map(compact_) %>%
purrr::flatten() %>%
tibble::tibble(
id = purrr::`%||%`(names(.x), seq_along(.x)),
return = names(.), output = .)

return = names(.), output = .
)

# Flatten results if necessary
if (.flatten) {

n_error <- length(pout$return[pout$return == "error"])
if (n_error > 0) {
warning(
"Since '.flatten = TRUE', a total of ", n_error,
" errors are being ignored", call. = FALSE)
" errors are being ignored",
call. = FALSE
)
}

pout <- pout %>%
dplyr::filter(return != "error") %>%
dplyr::select(-return) %>%
dplyr::select(-return) %>%
tidyr::unnest()

if (ncol(pout) == 1) {
pout <- dplyr::pull(pout, output)
}
}

return(pout)
}

Expand Down
Loading

0 comments on commit a1fa097

Please sign in to comment.