abjur / abjutils Goto Github PK
View Code? Open in Web Editor NEWUseful functions for the Brazilian Jurimetrics Association
Home Page: https://abjur.github.io/abjutils
License: Other
Useful functions for the Brazilian Jurimetrics Association
Home Page: https://abjur.github.io/abjutils
License: Other
Bom, como ambos somos BR, não me importei em escrever uma issue em inglês =/
Voltando ao assunto: a função janitor::clean_names()
recebe como input um objeto do tipo data.frame. Sei que ela e a rm_accent()
tem objetivos diferentes, mas pensei em como seria legal poder usar a última dentro de um pipeline só:
df %>% clean_names() %>% rm_accent()
Doesn't work:
f <- function(x) tibble::tibble()
abjutils::pvec(1:4, f)
#> Error: Tibble columns must have consistent lengths, only values of length one are recycled:
#> * Length 0: Columns `return`, `output`
#> * Length 4: Column `id`
Created on 2019-02-21 by the reprex package (v0.2.1)
Curiously, this works:
f <- function(x) tibble::tibble(a = "a")[-1,]
abjutils::pvec(1:4, f)
#> # A tibble: 4 x 3
#> id return output
#> <int> <chr> <list>
#> 1 1 result <tibble [0 × 1]>
#> 2 2 result <tibble [0 × 1]>
#> 3 3 result <tibble [0 × 1]>
#> 4 4 result <tibble [0 × 1]>
Created on 2019-02-21 by the reprex package (v0.2.1)
pvec()
works like a purrr::map_dfr()
with .id = "id"
.
Hence, this is the desired behavior
purrr::map_dfr(letters, tibble::enframe, .id = "id")
#> # A tibble: 26 x 3
#> .id name value
#> <chr> <int> <chr>
#> 1 1 1 a
#> 2 2 1 b
#> 3 3 1 c
#> 4 4 1 d
#> 5 5 1 e
#> 6 6 1 f
#> 7 7 1 g
#> 8 8 1 h
#> 9 9 1 i
#> 10 10 1 j
#> # ... with 16 more rows
names(letters) <- letters
purrr::map_dfr(letters, tibble::enframe, .id = "id")
#> # A tibble: 26 x 3
#> .id name value
#> <chr> <int> <chr>
#> 1 a 1 a
#> 2 b 1 b
#> 3 c 1 c
#> 4 d 1 d
#> 5 e 1 e
#> 6 f 1 f
#> 7 g 1 g
#> 8 h 1 h
#> 9 i 1 i
#> 10 j 1 j
#> # ... with 16 more rows
something like
f <- function(x) basename(tools::file_path_sans_ext(x))
what name should we use?
Hi there, I am working on the next version of furrr and your package has come up in my revdeps as having an issue.
The warning that I get is:
'::' or ':::' import not declared from: ‘lifecycle’
I see that you used to use furrr in this pvec()
function, which has now been deprecated
https://github.com/abjur/abjutils/blob/master/R/pvec.R
Since it has been deprecated for awhile, I think the easiest solution would be for you to mark it as .Defunct()
, and then remove all usage of furrr from the package, or to remove the function altogether.
If you are not ready for that, then there are two things that I will need your help with:
This global override of furrr::future_options()
is what causes the warning.
Line 91 in cc3ec0c
That function has now been soft deprecated in favor of furrr::furrr_options()
(to free up that name for future to use if it wants to). Internally, my future_options()
now calls a function from the lifecycle package. Since you have assigned my function directly into one of yours, R CMD Check found that you haven't Import-ed the lifecycle package, and it returned the above warning.
Since you only Suggest furrr, the easiest thing to do here is probably to just set your .options
argument to default to NULL
, and inside pvec()
you would call:
if (is.null(.options)) {
.options <- furrr::future_options()
}
Then you'd remove the override of furrr:future_options()
on line 91.
This second point is optional, but would be good practice. Since you now only Suggest furrr, it is unsafe to have any function in your package that calls a furrr::
function without first checking if furrr is installed. The easiest way to do that is to put this at the top of pvec()
if (!rlang::is_installed("furrr")) stop("The furrr package must be installed to use this function")
Line 74 in 21adc74
I think pvec()
should work like purrr::map_dfr()
when .flatten = TRUE
# devtools::install_github("abjur/abjutils")
fun <- function(x) {
Sys.sleep(1)
mtcars
}
res <- abjutils::pvec(letters, fun)
#>
Progress: ──────────── 100%
Progress: ───────────────────────── 100%
Progress: ───────────────────────────────────── 100%
Progress: ────────────────────────────────────────────────── 100%
Progress: ────────────────────────────────────────────────── 100%
Progress: ─────────────────────────────────────────────────────────────── 100%
Progress: ─────────────────────────────────────────────────────────────────────────── 100%
Progress: ─────────────────────────────────────────────────────────────────────────── 100%
Progress: ────────────────────────────────────────────────────────────────────────────────── 100%
Progress: ────────────────────────────────────────────────────────────────────────────────── 100%
res
#> # A tibble: 26 x 3
#> id return output
#> <int> <chr> <list>
#> 1 1 result <data.frame [32 × 11]>
#> 2 2 result <data.frame [32 × 11]>
#> 3 3 result <data.frame [32 × 11]>
#> 4 4 result <data.frame [32 × 11]>
#> 5 5 result <data.frame [32 × 11]>
#> 6 6 result <data.frame [32 × 11]>
#> 7 7 result <data.frame [32 × 11]>
#> 8 8 result <data.frame [32 × 11]>
#> 9 9 result <data.frame [32 × 11]>
#> 10 10 result <data.frame [32 × 11]>
#> # ... with 16 more rows
res <- abjutils::pvec(letters, fun, .flatten = TRUE)
#>
Progress: ──────────── 100%
Progress: ───────────────────────── 100%
Progress: ───────────────────────────────────── 100%
Progress: ────────────────────────────────────────────────── 100%
Progress: ────────────────────────────────────────────────── 100%
Progress: ─────────────────────────────────────────────────────────────── 100%
Progress: ─────────────────────────────────────────────────────────────────────────── 100%
Progress: ─────────────────────────────────────────────────────────────────────────── 100%
Progress: ────────────────────────────────────────────────────────────────────────────────── 100%
Progress: ────────────────────────────────────────────────────────────────────────────────── 100%
#> Error in eval_tidy(enquo(var), var_env): object 'output' not found
Also, should we assume that there will be no errors when .flatten = TRUE
?
Since the latest change to pvec
, errors are being reported as results and appear as <NULL>
.
Hello, I'm preparing the release of purrr 0.3.1 and I see this revdep failure:
https://github.com/tidyverse/purrr/blob/13ea8bfbf52696d12ba0453a241434b64e4a8066/revdep/problems.md
I think you have already fixed this 8 months ago in 7452d1b but this hasn't been pushed to CRAN yet. I'm planning to release purrr in 2 weeks.
You could do a preemptive fix release, or wait until purrr 0.3.1 is out. With that version, I think you can skip the unlist()
entirely because modify("foo", function(...) "bar")
now returns the same type as the input (here a character vector), as it always should have.
Prepare for release:
devtools::build_readme()
urlchecker::url_check()
devtools::check(remote = TRUE, manual = TRUE)
devtools::check_win_devel()
rhub::check_for_cran()
revdepcheck::revdep_check(num_workers = 4)
cran-comments.md
Submit to CRAN:
usethis::use_version('patch')
devtools::submit_cran()
Wait for CRAN...
usethis::use_github_release()
usethis::use_dev_version()
Oi, pessoal. Tudo bem?
Pesquisei aqui, mas não consegui descobrir. O pacote abjutils
tem alguma função para pegar um CPF comum (111.222.333-67
) ou (11122233367
) e transformar em CPF mascarado (***.222.333-**
)?
Obrigada!
if cores = 1 do not use parallel backend and add progress bar. Maybe also a verbose option
FEATURE REQUEST: escape_unicode function works on the whole document including comments, which as far as know doesn't need to be escaped. Rstudioapi has the primary_selection() function that allows to get just the selection. My suggestion is to allow users to escape just the body of the function by selecting it instead of the whole document.
library(magrittr)
da <- tibble::tibble(
a = "1000315-72.2016.8.26.0156"
)
da %>%
abjutils::separate_cnj(a)
#> Warning: Prefixing `UQ()` with the rlang namespace is deprecated as of rlang 0.3.0.
#> Please use the non-prefixed form or `!!` instead.
#>
#> # Bad:
#> rlang::expr(mean(rlang::UQ(var) * 100))
#>
#> # Ok:
#> rlang::expr(mean(UQ(var) * 100))
#>
#> # Good:
#> rlang::expr(mean(!!var * 100))
#>
#> This warning is displayed once per session.
#> # A tibble: 1 x 6
#> N D A J T O
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 1000315 72 2016 8 26 0156
Created on 2020-09-10 by the reprex package (v0.3.0)
In the latest commit (0c4c89d), I added the with_*()
family of functions. They are supposed to wrap common functions in the purrr::map()
family to add new functionalities to them: parallelism, progress tracking and side effect capturing.
Unfortunately, some things aren't working as expected 👎 Parallelism doesn't work with imap()
because of the .y
placeholder, and nothing works with map_if()
because we don't deal with the predicate .p
.
Should we simply ignore the situations where the functions don't work or should we try to deal with these edge cases?
# Setup
fun <- function(x, y, z) { x + y + z }
fun2 <- function(x, y, z) { Sys.sleep(1); x + y + z }
l <- list(1, 2, 3, "a", 4, 5)
# Parallel functions
par_map <- with_parallelism(purrr::map)
par_imap <- with_parallelism(purrr::imap)
par_map_if <- with_parallelism(purrr::map_if)
# Parallel tests
par_map(1:10, fun, y = 1, z = 2)
par_map(1:10, ~.x+1)
par_map(1:10, ~fun(1, .x, 2))
par_imap(1:10, fun, z = 2)
par_imap(1:10, ~.x+.y) ### COMPLETELY WRONG
par_imap(1:10, ~fun(.y, .x, 2)) ### COMPLETELY WRONG
par_map_if(1:10, ~.x%%2==0, fun, y = 1, z = 2) ### DOESN'T WORK
par_map_if(1:10, ~.x%%2==0, ~.x+1) ### DOESN'T WORK
par_map_if(1:10, ~.x%%2==0, ~fun(1, .x, 2)) ### DOESN'T WORK
# Progress functions
pro_map <- with_progress(purrr::map)
pro_imap <- with_progress(purrr::imap)
pro_map_if <- with_progress(purrr::map_if)
# Progress tests
pro_map(1:10, fun2, y = 1, z = 2)
pro_map(1:10, ~{ Sys.sleep(1); .x+1 })
pro_map(1:10, ~fun2(1, .x, 2))
pro_imap(1:10, fun2, z = 2)
pro_imap(1:10, ~{ Sys.sleep(1); .x+.y })
pro_imap(1:10, ~fun2(.y, .x, 2))
pro_map_if(1:10, ~.x%%2==0, fun2, y = 1, z = 2) ### NO PROGRESS
pro_map_if(1:10, ~.x%%2==0, ~{ Sys.sleep(1); .x+1 }) ### NO PROGRESS
pro_map_if(1:10, ~.x%%2==0, ~fun2(1, .x, 2)) ### NO PROGRESS
# Possibly functions
pos_map <- with_possibly(purrr::map)
pos_imap <- with_possibly(purrr::imap)
pos_map_if <- with_possibly(purrr::map_if)
# Possibly tests
pos_map(l, fun, y = 1, z = 2)
pos_map(l, ~.x+1)
pos_map(l, ~fun(1, .x, 2))
pos_imap(l, fun, z = 2)
pos_imap(l, ~.x+.y)
pos_imap(l, ~fun(.y, .x, 2))
pos_map_if(l, ~.x%%2==0, fun, y = 1, z = 2) ### DOESN'T WORK
pos_map_if(l, ~.x%%2==0, ~.x+1) ### DOESN'T WORK
pos_map_if(l, ~.x%%2==0, ~fun(1, .x, 2)) ### DOESN'T WORK
This should i) clean the id, ii) check if it has 20 digits and iii) check if the digit is wright
ii) should raise a warning message and return FALSE
. iii) should return TRUE
or FALSE
abjutils::check_dig("0005268-75.2013.8.26.100")
f <- function(x) { if(runif(1)<.1) return(NULL) else return(mtcars)}
res <- abjutils::pvec(1:1000, f)
Error: Columns return, output must be length 1 or 1000, not 890, 890
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.