-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix as_label()
#103
Comments
Can't remember if it is still used or where but looking at the function it is meant to be called from a parent function. foo <- \(){
as_label("hello")
y <- 1
as_label(y)
}() I haven't tested this yet |
here are the occurrences it's used in:
if you look at all those occurrences, it seems that the intended use was for f <- function(a) {
as_label(a)
}
f("hello") # "hello"
f(hello) # "x" but if that's not the case, then |
Yes, would have to be. f <- function(x) {
as_label(x)
}
f(hello)
f("hello") My knowledge of metaprogramming in R is still limited, is this something we should keep anyways? What do you think? |
for our use-case, no, here's how you'd expect, say res$set(name = "xyz", value = 10) rarely will someone do: res$set(name = xyz, value = 10) unless they've defined xyz <- "xyz"
res$set(name = xyz, value = 10) that's why i say but assuming you'd expect someone to do #' Make label
#'
#' Cheap replacement for rlang::as_label to avoid dependency.
#' Must fix.
#'
#' @noRd
#' @keywords internal
as_label <- function(x) {
call <- match.call()
if (is.character(call[["x"]])) {
return(x)
}
deparse(substitute(x))
}
as_label(a) # "a"
as_label("b") # "b"
as_label(c) # "c"
f <- function(a) {
call <- match.call()
# pass value of 'a' as is:
do.call(what = "as_label", args = list(x = call[["a"]]))
}
f("hello") # "hello"
f(hello) # "hello"
f("something") # "something"
# if evaluation of value is needed:
x <- 10
do.call(what = "f", args = list(a = x)) # "10" but as far as i can tell, we do not need |
Thanks for sharing. I agree with you it's probably better to remove it |
this is how
as_label()
is currently defined:i'm a bit lost regarding how this function is supposed to work or what the expected output is. maybe we should add examples?
nevertheless, i believe it has a bug:
could it be that the intended results were these?
The text was updated successfully, but these errors were encountered: