I'm still confused by all the embrace, enquo, unquo, !! etc.
I want to create a different tibble based on the day of the week.
library(tidyverse)
library(lubridate)
Monday <- c("Bob", "Jim", "Jane")
Tuesday <- c("Roberto", "Maria", "Xochil")
# Assume today is Monday
expected <- tibble(staff = Monday)
days <- function(dow){
tibble(staff = !!dow). # I don't know how to wrap dow
}
dayofweek <- wday(today(), label = TRUE, abbr = FALSE)
days(dayofweek)
There should be some way to wrap 'dow' in the function so that it takes the dayofweek and when it is Monday, creates a tibble based on the Monday list.
What about if I want to pass an expression rather than a column name? e.g. pass say "year(survey_date)" or even "Year=year(survey_date)". I know the following won't work:
I know I could use eval(parse(text=expr)), but then the resulting tibble will have as its column name "eval(parse(text=expr))" rather than "Year" or "year(survey_date)"
I just posted something about enquo, so I don't totally understand. But a solution is to convert the expression to a symbol and use !! in the summarize for the LHS of the summarize and then eval(parse()). You also have to use the walrus := instead of a regular equals sign.
If you don't want the expression function as the name of the column then I would supply a string too. Instead of having to parse out the specific relevant information from the expression.