Coder Social home page Coder Social logo

abjutils's People

Contributors

athospd avatar azeloc avatar brunodaleffi avatar clente avatar jimhester avatar jjesusfilho avatar jtrecenti avatar katerine-dev avatar olivroy avatar rmhirota avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

abjutils's Issues

rm_accent() poderia retornar um dataframe se um input for um objeto desse tipo

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()

pvec() fails when output has zero length

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() should return names as id when they exist

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

Usage of furrr

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:

  1. This global override of furrr::future_options() is what causes the warning.

    future_options <- furrr::future_options

    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.

  2. 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")
    

pvec() with .flatten=TRUE does not work for data frames

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?

abjutils and purrr 0.3.1

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.

Release abjutils 0.3.2

Prepare for release:

  • Check current CRAN check results
  • Polish NEWS
  • 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)
  • Update cran-comments.md

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()

CPF mascarado

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!

Add selection to escape_unicode

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.

Warning quando eu rodo abjutils::separate_cnj()

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)

Problems in the with_*() family

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

Correct check_dig

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")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.