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, acallobject, or aNULL. A reference to an alternative (custom) function used to translate text. If acallobject is passed tointerface, it must be to operator::. Calls to methodTranslator$translate()are ignored and calls tointerfaceare extracted instead. See Details below.- tokens
A
data.framereturned byutils::getParseData(). It must always minimally contain columnsline1,col1,line2,col2, andtext.- 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
a
callto methodTranslator$translate()ora
callto a custom function referenced byinterface.
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.