I am trying to conditionally add a column to a data frame. I have a column named comments
which has a text-based on English and German languages. I basically want to detect the language and add a new column with a value en
or de
depending on the translation.
library(googleLanguageR)
df$language <- ifelse(df$comments %>%
gl_translate_detect() %>%
pull(language) == "en","en", "de"
)
However, I get
Error: NA/NaN argument
Expected:
title | comments | language
-----------------------------------
A | I like... | en
B | I wish... | en
C | Das ist.... | de
C | Es war... | de
C | Most of the... | en
...
EDIT: output of gl_translate_detect()
A tibble:1 x 4
confidence isReliable language text
<dbl> <lgl> <chr> <chr>
0.983067 FALSE de Dem ich mich.
