Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_attr and sys.function #271

Closed
inferentialist opened this issue Jun 11, 2024 · 1 comment
Closed

set_attr and sys.function #271

inferentialist opened this issue Jun 11, 2024 · 1 comment

Comments

@inferentialist
Copy link

inferentialist commented Jun 11, 2024

First, thank you for an incredibly useful package. I'm a big fan of magrittr and appreciative of the work that you do. This is the first time I've run into unexpected behavior, so here goes.

an edit: it seems like |> gets me the result I expected; so this is probably more appropriately addressed on stackoverflow. apologies!

I was hoping to call set_attr and pass it the result of sys.function. This doesn't work / no attribute is set. I'm using magrittr version 2.0.3.

  library(magrittr)
  f <- function() {
    "hello" %>%
      magrittr::set_attr("g", sys.function())
  }

  r <- f()

  #' this fails as attr(r, "g") returns NULL
  testthat::expect_true(
    is.function(attr(r, "g"))
  )

Experimenting, I found that I could get the expected result using attr<- in lieu of set_attr. Also, assigning to an intermediate variable, phi, in the execution environment, i.e., phi <- sys.function() , before calling set_attr with phi worked. This made me wonder if the issue might be related to #195. It's also possible (likely) that I have the wrong expectations. Please don't hesitate to point me back to any relevant documentation, and thanks for any clarity you can provide.

@lionel-
Copy link
Member

lionel- commented Jun 12, 2024

This is expected behaviour / a limitation of magrittr. But I see you've already found a couple of workarounds :-)

@lionel- lionel- closed this as completed Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants