From cc9cc43ec473dd408f2d1acffb432f9d14eb4283 Mon Sep 17 00:00:00 2001 From: "C. Lente" <7017340+clente@users.noreply.github.com> Date: Tue, 11 Aug 2020 16:41:26 -0300 Subject: [PATCH] Remove pvec --- DESCRIPTION | 4 +- NAMESPACE | 2 +- R/cnj.R | 2 +- R/pvec.R | 91 -------------------------------------------- R/utils_pipe.R | 11 ++++++ man/extract_parts.Rd | 2 +- man/lsos.Rd | 10 ++++- man/pipe.Rd | 12 ++++++ man/pvec.Rd | 38 ------------------ man/sample_cnj.Rd | 12 +++++- 10 files changed, 45 insertions(+), 139 deletions(-) delete mode 100644 R/pvec.R create mode 100644 R/utils_pipe.R create mode 100644 man/pipe.Rd delete mode 100644 man/pvec.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 53220de..b9adbff 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,11 +32,9 @@ Imports: Suggests: devtools, usethis, - furrr, - future, testthat Encoding: UTF-8 LazyData: TRUE Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate")) -RoxygenNote: 6.1.1 +RoxygenNote: 7.1.1 diff --git a/NAMESPACE b/NAMESPACE index 92dbcd5..b86ae97 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export("%>%") export(build_id) export(calc_dig) export(carf_build_id) @@ -17,7 +18,6 @@ export(gather_subjects) export(lsos) export(pattern_cnj) export(precision) -export(pvec) export(reais) export(rm_accent) export(sample_cnj) diff --git a/R/cnj.R b/R/cnj.R index b6346b0..3103d05 100644 --- a/R/cnj.R +++ b/R/cnj.R @@ -125,7 +125,7 @@ verify_cnj <- function(cnj) { #' @param parts String or string vector with desired parts (see **description**) #' #' @examples -#' { +#' \dontrun{ #' extract_parts("001040620018260004", "N") #' extract_parts("001040620018260004", c("N", "A", "O")) #' } diff --git a/R/pvec.R b/R/pvec.R deleted file mode 100644 index 336325a..0000000 --- a/R/pvec.R +++ /dev/null @@ -1,91 +0,0 @@ - -#' @title Verbose, parallel, and safe map-like -#' -#' @description Using the same argument notation as [purrr::map()], this function -#' iterates over a list of inputs `.x`, applying `.f` to each element. It -#' returns a tibble with the id, whether the function returned an error -#' and the output. -#' -#' @importFrom magrittr %>% -#' -#' @param .x A list or atomic vector -#' @param .f A function, formula, or atomic vector (see [purrr::map()]) -#' @param ... Other parameters passed on to `.f` -#' @param .cores Number of cores to use when multiprocessing -#' @param .progress Whether or not to display progress -#' @param .flatten If `TRUE`, the errors are filtered from the output, -#' 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()) { - .Deprecated("furrr::future_map") - - # 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]])) { - return(list(result = NULL)) - } - else { - if (length(x$result) == 0) { - return(list(result = NULL)) - } - return(purrr::compact(x)) - } - } - - # Process output - pout <- out %>% - purrr::map(compact_) %>% - purrr::flatten() %>% - dplyr::tibble( - id = purrr::`%||%`(names(.x), seq_along(.x)), - 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 - ) - } - - pout <- pout %>% - dplyr::filter(return != "error") %>% - dplyr::select(-return) %>% - tidyr::unnest() - - if (ncol(pout) == 1) { - pout <- dplyr::pull(pout, output) - } - } - - return(pout) -} - -# Get number of available cores -get_cores <- purrr::partial(future::availableCores, constraints = "multicore") - -# Import of future_options() -future_options <- furrr::future_options diff --git a/R/utils_pipe.R b/R/utils_pipe.R new file mode 100644 index 0000000..e79f3d8 --- /dev/null +++ b/R/utils_pipe.R @@ -0,0 +1,11 @@ +#' Pipe operator +#' +#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +#' +#' @name %>% +#' @rdname pipe +#' @keywords internal +#' @export +#' @importFrom magrittr %>% +#' @usage lhs \%>\% rhs +NULL diff --git a/man/extract_parts.Rd b/man/extract_parts.Rd index 3ed8dc1..9199785 100644 --- a/man/extract_parts.Rd +++ b/man/extract_parts.Rd @@ -25,7 +25,7 @@ parts of the IDs given the following correspondence: } } \examples{ -{ +\dontrun{ extract_parts("001040620018260004", "N") extract_parts("001040620018260004", c("N", "A", "O")) } diff --git a/man/lsos.Rd b/man/lsos.Rd index 926140d..f2e678d 100644 --- a/man/lsos.Rd +++ b/man/lsos.Rd @@ -4,8 +4,14 @@ \alias{lsos} \title{Improved list of objects} \usage{ -lsos(pos = 1, pattern, order.by = "Size", decreasing = TRUE, - head = TRUE, n = 10) +lsos( + pos = 1, + pattern, + order.by = "Size", + decreasing = TRUE, + head = TRUE, + n = 10 +) } \arguments{ \item{pos}{Where to look for the object (see "Details" in \code{\link[base:get]{base::get()}}'s diff --git a/man/pipe.Rd b/man/pipe.Rd new file mode 100644 index 0000000..52d6d19 --- /dev/null +++ b/man/pipe.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_pipe.R +\name{\%>\%} +\alias{\%>\%} +\title{Pipe operator} +\usage{ +lhs \%>\% rhs +} +\description{ +See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +} +\keyword{internal} diff --git a/man/pvec.Rd b/man/pvec.Rd deleted file mode 100644 index 8fee9c5..0000000 --- a/man/pvec.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pvec.R -\name{pvec} -\alias{pvec} -\title{Verbose, parallel, and safe map-like} -\usage{ -pvec(.x, .f, ..., .cores = get_cores(), .progress = TRUE, - .flatten = FALSE, .options = future_options()) -} -\arguments{ -\item{.x}{A list or atomic vector} - -\item{.f}{A function, formula, or atomic vector (see \code{\link[purrr:map]{purrr::map()}})} - -\item{...}{Other parameters passed on to \code{.f}} - -\item{.cores}{Number of cores to use when multiprocessing} - -\item{.progress}{Whether or not to display progress} - -\item{.flatten}{If \code{TRUE}, the errors are filtered from the output, -and the returned object is flattened (a vector, a list, or a tibble)} - -\item{.options}{Options passed on to \code{\link[furrr:future_map]{furrr::future_map()}} -(\code{\link[furrr:future_options]{furrr::future_options()}} by default)} -} -\value{ -A tibble with 3 columns: input, return, and output -} -\description{ -Using the same argument notation as \code{\link[purrr:map]{purrr::map()}}, this function -iterates over a list of inputs \code{.x}, applying \code{.f} to each element. It -returns a tibble with the id, whether the function returned an error -and the output. -} -\seealso{ -\code{\link[purrr:map]{purrr::map()}}, \code{\link[furrr:future_map]{furrr::future_map()}}, \code{\link[furrr:future_options]{furrr::future_options()}} -} diff --git a/man/sample_cnj.Rd b/man/sample_cnj.Rd index df713e3..244a7c7 100644 --- a/man/sample_cnj.Rd +++ b/man/sample_cnj.Rd @@ -4,8 +4,16 @@ \alias{sample_cnj} \title{Generate sample Brazilian lawsuit identification numbers} \usage{ -sample_cnj(n, foros, anos, orgao, tr, first_dig = "0", - sample_pars = TRUE, return_df = TRUE) +sample_cnj( + n, + foros, + anos, + orgao, + tr, + first_dig = "0", + sample_pars = TRUE, + return_df = TRUE +) } \arguments{ \item{n}{A non negative integer giving the number of codes to generate}