Should be:

```{r}
if (is.numeric(values) && !keep.as.numeric) {
  values <- as.character(values)
}
```