translate_df: Translates a column in a dataframe.

View source: R/translate_df.R

translate_dfR Documentation

Translates a column in a dataframe.

Description

Translates a column in a dataframe.

Usage

translate_df(dataset = NULL, column.name = NULL, source.lang = "DE",
  target.lang = "EN", add.source.lang = FALSE, auth_key = NULL,
  url = "https://api.deepl.com/v2/translate?text=")

Arguments

dataset

Dataframe with column of class character.

column.name

Name of column that should be translated.

source.lang

Source language. Either "detect" or one of "EN", "FR", etc.

target.lang

Target language. One of "EN", "FR", etc.

add.source.lang

A logical. If TRUE adds the preset or detected language for each translation. FALSE (default) adds nothing.

auth_key

Your API key.

url

Url to DeepL API.

Value

Dataframe with original columns and translated column. add.source.lang = TRUE adds additional column "source_lang".

Examples

## Not run: 
  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")

## End(Not run)

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