Using recode on a dot

If have encountered a problem when trying to use recode on a dot. This attempt

library(tidyverse)
x <- c("a", ",", ".")
recode(x, a = "A", "," = "comma", "." = "dot")

fails for the dot (works for "a" and ",") with error message

Error: Argument 2 must be named, not unnamed

Escaping the dot does clear the error, but the dot is not recoded.

recode(x, a = "A", "," = "comma", "\\." = "dot")
[1] "A"     "comma" "."   

Any ideas how to recode a dot?

Interesting. I think it should work in slightly adapted form (but it does not!) :

recode(x, a = "A", "," = "comma", `.` = "dot")

I have tried (too long :sob:) to get it working, but see no other way then to change the dot outside the recode.

Hope that one of the other readers has a solution. Again: interesting case.

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