Hi,
In the code below I have a list containing a single value. I want to check if each value is a double scaler. If not, then I want to print a name of that variable. Currently it is printing value to the variable and not the name of variable. I know the reason why it is so. But do not know how to solve this. Any help would be appriciated.
Thanks.
purrr::map(list(A = "xyz" , B = 1, C = 3 , D = 4,E = 5) ,
function(x){
x_enquo = rlang::enquo(x)
x_name <- rlang::quo_name(x_enquo)
if(!rlang::is_scalar_double(x)){
stop(glue::glue("{x_name} must be a double of length 1."))
}
})
#> Error in .f(.x[[i]], ...): xyz must be a double of length 1.
Created on 2021-09-02 by the reprex package (v2.0.1)
Correction
Instead of a list, the input is a vector as shown
A = "XYZ"
B = 2
C= 3
D = 4
purrr::map(c(A,B,C,D) ,
function(x){
x_enquo = rlang::enquo(x)
x_name <- rlang::quo_name(x_enquo)
if(!rlang::is_scalar_double(x)){
stop(glue::glue("{x_name} must be a double of length 1."))
}
})
#> Error in .f(.x[[i]], ...): XYZ must be a double of length 1.
Created on 2021-09-02 by the reprex package (v2.0.1)