moodymudskipper / tags

A collection of tags built using the package tag
GNU General Public License v3.0
8 stars 0 forks source link

with_pb doesn't work when map is inside a function #22

Closed codetrainee closed 5 years ago

codetrainee commented 5 years ago

See below:

library(tags)
#> Loading required package: tag
library(purrr)

map(1:5, ~{Sys.sleep(1); .x})
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 2
#> 
#> [[3]]
#> [1] 3
#> 
#> [[4]]
#> [1] 4
#> 
#> [[5]]
#> [1] 5

with_pb$map(1:5, ~{Sys.sleep(1); .x})
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 2
#> 
#> [[3]]
#> [1] 3
#> 
#> [[4]]
#> [1] 4
#> 
#> [[5]]
#> [1] 5

test <- function(x) map(x, ~{Sys.sleep(1); .x})

test(1:5)
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 2
#> 
#> [[3]]
#> [1] 3
#> 
#> [[4]]
#> [1] 4
#> 
#> [[5]]
#> [1] 5

test_pb <- function(x) with_pb$map(x, ~{Sys.sleep(1); .x})

test_pb(1:5)
#> Error in eval(ARGS[[1]]): object 'x' not found

Created on 2019-05-24 by the reprex package (v0.3.0)

moodymudskipper commented 5 years ago

Thanks @codetrainee , I badly need unit tests, and reports like yours, hopefully I'll manage to make the package more reliable in the upcoming weeks,

I fixed this by using eval.parent instead of eval in a couple places in the tag definition. It's likely that other similar mistakes are present in other tags, don't hesitate to report further meanwhile and I'll fix them asap.

moodymudskipper commented 5 years ago

I did a fast pass on all functions and hopefully they'll work ok now.

moodymudskipper commented 5 years ago

@codetrainee the packages tag and tags went through massive changes, it's hopefully more robust now!

The many changes include the renaming of with_pb to progressing to have more consistent and be more explicit about it being a wrapper on progress