| Title: | Translates R Help Documentation using Large Language Models |
|---|---|
| Description: | Translates R help documentation on the fly by using a Large Language model of your choice. If you are using 'RStudio' or 'Positron' the translated help will appear in the help pane. |
| Authors: | Edgar Ruiz [aut, cre], Posit Software, PBC [cph, fnd] (ROR: <https://ror.org/03wc8by49>) |
| Maintainer: | Edgar Ruiz <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9000 |
| Built: | 2026-06-02 15:14:10 UTC |
| Source: | https://github.com/mlverse/lang |
The ? and help functions are drop-in replacements for those in the
utils package. They automatically translate help to the language specified
by the LANG or LANGUAGE environment variables, or by lang_use().
# help(topic, package = NULL, ...) # ?e2 # e1?e2# help(topic, package = NULL, ...) # ?e2 # e1?e2
topic |
A name or character string specifying the help topic. |
package |
A name or character string specifying the package in which to search for the help topic. If NULL, search all packages. |
... |
Additional arguments to pass to |
e1 |
First argument to pass along to |
e2 |
Second argument to pass along to |
Translates a given topic into a target language. It uses the lang argument
to determine which language to translate to. If not passed, this function will
look for a target language in the LANG and LANGUAGE environment variables, or
if something has been passed to the .lang argument in lang_use(), to
determine the target language. If the target language is English, no translation
will be processed, so the help returned will be the original package's
documentation.
lang_help( topic, package = NULL, lang = NULL, context_size = NULL, type = getOption("help_type") )lang_help( topic, package = NULL, lang = NULL, context_size = NULL, type = getOption("help_type") )
topic |
A character string specifying the help topic to translate. |
package |
The R package to look for the topic, if not provided the function will attempt to find the topic based on the loaded packages. |
lang |
A character vector language to translate the topic to |
context_size |
Maximum number of words for the context summary included
with each translation request. Set to |
type |
Produce "html" or "text" output for the help. It defaults to
|
Original or translated version of the help documentation in the output type specified
library(lang) lang_use("ollama", "llama3.2", seed = 100) lang_help("lang_help", lang = "spanish", type = "text")library(lang) lang_use("ollama", "llama3.2", seed = 100) lang_help("lang_help", lang = "spanish", type = "text")
Allows us to specify the back-end provider, model to use during the current R session. The target language is not processed by the function, as in converting "english" to "en" for example. The value is passed directly to the LLM, and it lets the LLM interpret the target language.
lang_use( backend = NULL, model = NULL, .cache = NULL, .lang = NULL, .context_size = NULL, .silent = FALSE, ... )lang_use( backend = NULL, model = NULL, .cache = NULL, .lang = NULL, .context_size = NULL, .silent = FALSE, ... )
backend |
"ollama" or an |
model |
The name of model supported by the back-end provider |
.cache |
Character path where translations are cached. Set to |
.lang |
Target language to translate to. This will override values found in the LANG and LANGUAGE environment variables. |
.context_size |
Maximum number of words for the context summary
included with each translation request. Set to |
.silent |
Boolean flag that controls whether there is output to the console. Defaults to FALSE. |
... |
Additional arguments that this function will pass down to the
integrating function. In the case of Ollama, it will pass those arguments to
|
Invisibly returns NULL. Prints the current configuration to the
console.
library(lang) # Using an `ellmer` chat object lang_use(ellmer::chat_openai(model = "gpt-4o")) # Using Ollama directly lang_use("ollama", "llama3.2", seed = 100) # Turn off cache by setting `.cache` to "" lang_use("ollama", "llama3.2", seed = 100, .cache = "") # Use `.lang` to set the target language to translate to, # it will be set for the current R session lang_use("ollama", "llama3.2", .lang = "spanish") # Use `.silent` to avoid console output lang_use("ollama", "llama3.2", .lang = "spanish", .silent = TRUE) # To see current settings, simply call the function lang_use()library(lang) # Using an `ellmer` chat object lang_use(ellmer::chat_openai(model = "gpt-4o")) # Using Ollama directly lang_use("ollama", "llama3.2", seed = 100) # Turn off cache by setting `.cache` to "" lang_use("ollama", "llama3.2", seed = 100, .cache = "") # Use `.lang` to set the target language to translate to, # it will be set for the current R session lang_use("ollama", "llama3.2", .lang = "spanish") # Use `.silent` to avoid console output lang_use("ollama", "llama3.2", .lang = "spanish", .silent = TRUE) # To see current settings, simply call the function lang_use()