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

rlang::env_binding_are_lazy() fails when a names() method is defined #1783

Open
moodymudskipper opened this issue Mar 14, 2025 · 1 comment

Comments

@moodymudskipper
Copy link

moodymudskipper commented Mar 14, 2025

env <- rlang::env(x = 1)
class(env) <- "foo"
names.foo <- function(x) "y"
names(env)
#> [1] "y"
rlang::env_binding_are_lazy(env)
#> Error in env_binding_types(env, nms): no binding for "y"

Created on 2025-03-14 with reprex v2.1.0

Real life example with reticulate objects :

library(reticulate)
sentence_transformers <- import("sentence_transformers")
model <- sentence_transformers$SentenceTransformer("all-MiniLM-L6-v2")
sentences <- c("This is an example sentence.", "Another sentence.")
embeddings <- model$encode(sentences)
rlang::env_binding_are_lazy(embeddings)
#> Error in env_binding_types(env, nms): no binding for "all"

Created on 2025-03-14 with reprex v2.1.0

I think ls(, all.names = TRUE, sorted = FALSE) should be used instead of env_names()

Edit: same for env_binding_are_locked()

@moodymudskipper
Copy link
Author

Luckily we have a nms arg so if we provide the correct names there it works

env <- rlang::env(x = 1)
class(env) <- "foo"
names.foo <- function(x) "y"
rlang::env_binding_are_lazy(env, ls(env, all.names = TRUE, sorted = FALSE))
#>     x 
#> FALSE

Created on 2025-03-14 with reprex v2.1.0

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

1 participant