ERROR: This tidyselect interface doesn't support predicates yet.

To whom it may concern,

Hello, this is Martin.

I am new in R and I am having a problem with the function unite in the package tidyverse.

I am trying to unite three variables (day, month, year) into a newone (birth_date) that would display dd_mm_yyyy. I use the function unite but I have a problem with missing values. It gives me:

Proof1 <- unite(Proof1, birth_date, day:year, sep = "_", remove = FALSE, na.rm = TRUE)
Errore: This tidyselect interface doesn't support predicates yet.
:information_source: Contact the package author and suggest using eval_select().
Run rlang::last_error() to see where the error occurred.

If I do set na.rm=FALSE, then when there are missing values in the three initial columns I want to unite, it just creates something like this: "NA_NA_NA", so it does not identify missing values. I would like those values to appear as missing values.

Anyone has a solution for this?
Thanks very much!

Mar

Try this change:

Proof1 <- unite(Proof1, "birth_date", day:year, sep = "_", remove = FALSE, na.rm = TRUE)

Thank you martin.R!

I tried but it still gives me the same error. I guess it is related with missing values. Any other idea?

Thanks again,

Mar

You'll need to provide your example data in that case via e.g. dput().

Does the following code give you a tidyselect error ?

library(tidyverse)
df <- data.frame(day=c(1,2,3),
                 month=c(7,NA,9),
                 year=c(2020,2020,2020),
                 somedata=LETTERS[1:3])

df %>% unite(created_date,day:year,remove = FALSE)

Hi,

thank you for your answers. I try to reformulate the problem (I am not very familiar with dput(), sorry, I am very new with R). Here is an example dataset.

Schermata 2020-04-28 alle 16.04.29

I have columns Day, Month and Year and I want to create variable birth_date. When I have missing values in at least one of the three columns (Day, Month, Year), I'd like to have a missing value in the new variable as well.

When I use the function:
Proof1 <- unite(Proof1, birth_date, day:year, sep = "_", remove = FALSE, na.rm = TRUE)
I get the following error:
Errore: This tidyselect interface doesn't support predicates yet.
:information_source: Contact the package author and suggest using eval_select() .
Run rlang::last_error() to see where the error occurred.

I hope this is a bit clearer. Thank you for your help!

Mar

Hi,

Thanks for helping.
The code does not give me the error any more, but it does not solve the problem with missing values, plus it creates the variable in a new dataset.
Any other idea?

Mar

run your code up to the line before you would use unite().
then run

dput(head(Proof1,n=20))

and paste the results here.

here it is:
structure(list(day = c(NA, "01", "02", "08", NA, "01", "02",
"08", NA, "01", "02", "08", NA, "01", "02", "08", NA, "01", "02",
"08"), month = c(NA, "03", "09", "09", NA, "03", "09", "09",
NA, "03", "09", "09", NA, "03", "09", "09", NA, "03", "09", "09"
), year = c(NA, "2008", "2008", "2010", NA, "2008", "2008", "2010",
NA, "2008", "2008", "2010", NA, "2008", "2008", "2010", NA, "2008",
"2008", "2010")), row.names = c(NA, -20L), class = c("tbl_df",
"tbl", "data.frame"))

thanks,

Mar

if you use the lubridate package, it can transform text representations of dates to R date dtypes, failures will get an NA.

library(tidyverse)
library(lubridate)
df2 <- df %>% 
  unite(created_date_txt,day:year,remove = FALSE) %>% 
  mutate(created_date = lubridate::dmy(created_date_txt))

Thanks nirghrahamuk.
When implementing your suggestion it gives me this error:
Error in UseMethod("unite_") :
no applicable method for 'unite_' applied to an object of class "function"

df should be the name of your input dataframe

Thanks for your help. It was really useful.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.