knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

deeplr

The DeepL Translator made headlines for providing better translations than Google etc. deeplr is a quick & dirty coded package that contains functions - translate_vec() and translate_df() - that access the DeepL API. I was inspired by the translateR package package.

To access the API you need to get your own API key from deeplr: https://www.deepl.com/api-contact.html.

Beware of the API request limits. See https://www.deepl.com/api-reference.html.

Installation: How do I get the package?

# Development version
# install.packages("devtools")
devtools::install_github("paulcbauer/deeplr")

Example: How do I use the package?

You can feed translate_vec() with a single string, a vector of strings (class "character"). You can feed translate_df() with a dataframe that contains a column of class "character".

# Load the package
  library(deeplr)

# Translate a single string/character vector
  dat <- c("La seule facon de savoir ce qui se passe est de perturber le systeme.",
           "The whole problem with the world is that fools are always so certain of themselves")

# Without language detection and without adding set/detected source language.
  translate_vec(dataset = dat,
                source.lang = "EN",
                target.lang = "DE",
                auth_key = "enter you auth key here")

  dat <- c("A dog.",
           "Un chien.",
           "Un perro.",
           "Un cane.",
           "Een hond.")

# With language detection and with adding set/detected source language.
  translate_vec(dataset = dat,
                source.lang = "detect",
                target.lang = "DE",
                add.source.lang = TRUE,
                auth_key = "enter you auth key here")





# Translate a column in a dataframe
  dat <- data.frame(text = c("La seule facon de savoir ce qui se passe est de perturber
                              le systeme.",
                              "The whole problem with the world is that fools are always so
                              certain of themselves"))


# Without language detection and without adding set/detected source language.
  translate_df(dataset = dat,
               column.name = "text",
               source.lang = "EN",
               target.lang = "DE",
               auth_key = "enter you auth key here")

  dat <- data.frame(text = c("A dog.",
                             "Un chien.",
                             "Un perro.",
                             "Un cane.",
                             "Een hond."))

# With language detection and with adding set/detected source language.
  translate_df(dataset = dat,
               column.name = "text",
               source.lang = "detect",
               target.lang = "DE",
               add.source.lang = TRUE,
               auth_key = "enter you auth key here")
  # well...

Next steps

License

License: CC BY-NC-SA 4.0



paulcbauer/deeplr documentation built on April 26, 2022, 3:38 a.m.