mutate_if() is another option.
mutate_if()
DF <- DF |> mutate_if(is.character, as.factor) |> mutate_if(is.factor, as.numeric)