Coder Social home page Coder Social logo

loopurrr's Introduction

πŸ“’ Hi there πŸ‘‹ I’m Tim!

Followers on Mastodon StackOverflow Profile Connect on LinkedIn Buy me a tea

I’m a Senior Data Scientist πŸ₯Ό working in insurance πŸ“ with a focus on customer experience πŸ€— data.

Tim’s GitHub stats

In case my contributions
show a lot of inactivity:
Note, I often avoid working
on the main branches πŸ˜…

If you want to support me, buy me a tea πŸ΅πŸ˜‹

Credits:

The β€œgreen tea” logo in the β€œbuy me a tea” badge above was created by FELIX FX from Noun Project and is licensed under CC BY 3.0

loopurrr's People

Contributors

timteafan 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  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

Forkers

ddotta

loopurrr's Issues

Error when .f contains curly braces

map(1:4,  function(x) {
  x
  }) %>% as_loop()
#> Error: 'text' should either be length 1, or same length as 'ranges'

This error is probably raised in insert_and_reformat_text.

Remove `tryCatch` when `as_loop` is called with a map extractor function that uses names

We don't need tryCatch as long as .inp1 is a name.

It's only needed when .inp1 is an integer which might cause an out of bound error.

# --- convert: `map(l1, "a")` as loop --- #
.inp1 <- "a"
out <- vector("list", length = length(l1))

for (i in seq_along(l1)) {
  .tmp <- tryCatch({l1[[i]][[.inp1]]
  }, error = function(e) {})
  if (!is.null(.tmp)) out[[i]] <- .tmp
}
# --- end loop --- #

Add safety checks of `.f`

It is possible that the function in .f uses the same variable as specified in idx which defaults to i. There should be a check in place, checking this , raising an error with the advise to set idx to a variable that is not used in .f.

map(1:4,  function(x) {
  i <- 5
  x + i
  }) %>% as_loop()

Need to solve #6 before solving this issue.

There also be other safety checks in place for all possible inputs like .sel .inp1 etc.

Error: 'ranges' should be a list of 4-element integer vectors

Sometimes calls to as_loop through the following error:

Error: 'ranges' should be a list of 4-element integer vectors

It is not clear to me yet, when this happens. Rerunning the code often will resolve the error.

This is caused by the output function when in RStudio.

Need to give it a deeper look.

only `~.x` in `.f` not working

Find the reason why this is not working:

map(1:5, ~.x) %>% as_loop
#> Error in expr[[i]] : object of type 'symbol' is not subsettable

`as_loop()` doesn't work correctly on `pmap`

library(loopurrr)
#> Loading required package: purrr

x <- list(1, 1, 1)
y <- list(10, 20, 30)
z <- list(100, 200, 300)
a <- list(x, y, z)

# expected
pmap(a, sum)
#> [[1]]
#> [1] 111
#> 
#> [[2]]
#> [1] 221
#> 
#> [[3]]
#> [1] 331

# doesn't work
pmap(a, sum) %>% as_loop()
#> Error in !is_clipr: invalid argument type

# works!
pmap(list(x, y, z), sum) %>% as_loop()
#> Error in !is_clipr: invalid argument type

Created on 2022-10-05 by the reprex package (v0.3.0)

`for` loop produces different result as `map` due to lazy evaluation

R's lazy evaluation can lead to different results when translating map function calls to for loops. Below is one example that Claus Wilke provided on Twitter.

Lets think about, whether there is someway to force evaluation programmatically to produce the same result as map and if not, this needs to be mentioned an a vignette together with other caveats and quirks of as_loop().

library(loopurrr)
#> Loading required package: purrr

make_add <- function(n) {
  function(x) {
    x + n
  }
}

idx <- as.list(1:5)

z <- map(idx, make_add)

map(idx, make_add) %>% 
   as_loop()

# --- convert: `map(idx, make_add)` as loop --- #
out <- vector("list", length = length(idx))

for (i in seq_along(idx)) {
  out[[i]] <- make_add(idx[[i]])
}
# --- end loop --- #

z[[1]](10)
#> [1] 11
out[[1]](10)
#> [1] 15

Created on 2022-04-05 by the reprex package (v0.3.0)

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.