Skip to contents

Find and extract source text that must be translated from a single file or a set of R expr tokens.

Arguments listed below are not explicitly validated for efficiency.

Usage

find_source_in_file(
  path = "",
  encoding = "UTF-8",
  verbose = getOption("transltr.verbose", TRUE),
  algorithm = algorithms(),
  interface = NULL
)

find_source_in_exprs(
  tokens = utils::getParseData(),
  path = "",
  algorithm = algorithms(),
  interface = NULL
)

find_source_exprs(path = "", encoding = "UTF-8")

is_source(x, interface = NULL)

Arguments

path

A non-empty and non-NA character string. A path to an R source script.

encoding

A non-empty and non-NA character string. The source character encoding. In almost all cases, this should be UTF-8. Other encodings are internally re-encoded to UTF-8 for portability.

verbose

A non-NA logical value. Should progress information be reported?

algorithm

A non-empty and non-NA character string equal to "sha1", or "utf8". The algorithm to use when hashing source information for identification purposes.

interface

A name, a call object, or a NULL. A reference to an alternative (custom) function used to translate text. If a call object is passed to interface, it must be to operator ::. Calls to method Translator$translate() are ignored and calls to interface are extracted instead. See Details below.

tokens

A data.frame returned by utils::getParseData(). It must always minimally contain columns line1, col1, line2, col2, and text.

x

Any R object.

Value

find_source_in_file() and find_source_in_exprs() return a list of Text objects. It may contain duplicated elements, depending on the extracted contents.

find_source_exprs() returns a subset of the output of utils::getParseData(). Only expr tokens are returned.

is_source() returns a logical value.

Details

find_source_in_exprs() silently skips parsing errors. See find_source() for more information.

is_source() checks if an object conceptually represents a source text. This can either be

Calls to method Translator$translate() that include ... in their argument(s) are ignored. Such calls are part of the definition of a custom interface and should not be extracted.