
Prepending unique utterance identifiers
Source:R/prepend_ids_to_source.R
, R/prepend_ids_to_sources.R
prepending_uids.Rd
This function prepends unique utterance identifiers to each
utterance (line) in a source. Note that you'll probably want
to clean the sources using clean_sources()
first.
Usage
prepend_ids_to_source(
input,
output = NULL,
origin = Sys.time(),
follow = NULL,
followBy = NULL,
rlWarn = rock::opts$get(rlWarn),
preventOverwriting = rock::opts$get(preventOverwriting),
encoding = rock::opts$get(encoding),
silent = rock::opts$get(silent)
)
prepend_ids_to_sources(
input,
output = NULL,
outputPrefix = "",
outputSuffix = "_withUIDs",
origin = Sys.time(),
follow = NULL,
followBy = NULL,
uidSpacing = NULL,
preventOverwriting = rock::opts$get(preventOverwriting),
encoding = rock::opts$get(encoding),
silent = rock::opts$get(silent)
)
Arguments
- input
The filename or contents of the source for
prepend_ids_to_source
; and the directory containing the sources, or a list of character vectors, forprepend_ids_to_sources
.- output
The filename where to write the resulting file for
prepend_ids_to_source
and the directory where to write the resulting files forprepend_ids_to_sources
- origin
The time to use for the first identifier.
- follow
A vector of one or more UIDs (or a list; lists are recursively
unlist()
ed); the highest UID will be taken, converted to a timestamp, and used asorigin
(well, 0.01 second later), so that the new SQUIDs will follow that sequence (seesquids::squids()
).- followBy
When following a vector of UIDs, this can be used to specify the distance between the two vectors (see
squids::squids()
).- rlWarn
Whether to let
readLines()
warn, e.g. if files do not end with a newline character.- preventOverwriting
Whether to overwrite existing files (
FALSE
) or prevent that from happening (TRUE
).- encoding
The encoding of the file(s).
- silent
Whether to be chatty or quiet.
- outputPrefix, outputSuffix
The prefix and suffix to add to the filenames when writing the processed files to disk.
- uidSpacing
The number of UID spaces to leave between sources (in case more data may follow in with source).
Value
The source with prepended uids, either invisible (if output
if specified) or visibly (if not).
Examples
### Simple example
rock::prepend_ids_to_source(
"brief\nexample\nsource"
);
#> [1] "[[uid=7zz4g69c]] brief" "[[uid=7zz4g69d]] example"
#> [3] "[[uid=7zz4g69f]] source"
### Example including fake YAML fragments
longerExampleText <-
c(
"---",
"First YAML fragment",
"---",
"So this is an utterance (i.e. outside of YAML)",
"This, too.",
"---",
"Second fragment",
"---",
"Another real utterance outside of YAML",
"Another one outside",
"Last 'real utterance'"
);
rock::prepend_ids_to_source(
longerExampleText
);
#> [1] "---"
#> [2] "First YAML fragment"
#> [3] "---"
#> [4] "[[uid=7zz4g69c]] So this is an utterance (i.e. outside of YAML)"
#> [5] "[[uid=7zz4g69d]] This, too."
#> [6] "---"
#> [7] "Second fragment"
#> [8] "---"
#> [9] "[[uid=7zz4g69f]] Another real utterance outside of YAML"
#> [10] "[[uid=7zz4g69g]] Another one outside"
#> [11] "[[uid=7zz4g69h]] Last 'real utterance'"