Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Pipes of functions have broken environments #159

@HuwCampbell

Description

@HuwCampbell

Sorry if this appears a little obscure, it's causing me some difficulty.

I found this issue after you posted a review for hedgehog (ta!). Using the pipe I was having infinite recursion due to the environments being brought into functions incorrectly.

Here's a quick bug showing something similar

compose <- function(f, g) { function(x) g(f(x)) }
plus1   <- function(x) x + 1
compose(plus1, plus1)(5)
# [1] 7
plus2 <- plus1 %>% compose(plus1)
plus2(5)
# Error in g(f(x)) : could not find function "f"
plus2
# function(x) g(f(x))
# <environment: 0x7f977ecd1ea8>
as.list(environment(plus2))
# $f
# $f$value
# function (x) 
# g(f(x))
# <environment: 0x7f977ecd1ea8>
# 
# $f$visible
# [1] TRUE

# $g
# function (x) 
# x + 1

See above that f$value refers to g(f(x)), when it should be function(x) x + 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions