I am writing a generalized lookup function to execute against a tibble. When I run the code below, I get "Error: object 'x' not found"
My real function returns a different error message, but I think some guidance on this will help.
See the code below
library(dplyr)
library(tibble)
fruits <- tibble(
x = 1:5,
y = c("apple", "peach", "pear", "strawberry", "orange")
)
gLookup <- function(datasource, indexColumn, targetValue, lookupColumn){
datasource %>%
filter(indexColumn == targetValue) %>%
select(lookupColumn) %>%
unlist() %>%
unname
}
gLookup(fruits, x, 3, y)
I expect "pear" to be returned, but instead I get: Error: object 'x' not found