
Get Text File as Character String
getTextString.RdRetrieves a text file from the improve repository and loads it as a character string with metadata including caption and description. All lines are collapsed into a single string with newline separators.
Usage
getTextString(
ident,
from = pwd(),
addAsLink = TRUE,
caption = "",
description = "",
...
)Arguments
- ident
Path, resource ID, or entity ID of the text file. Can be a relative path (from current step), absolute path, or improve identifier
- from
Root path for resolving relative paths. Defaults to
pwd()(current step location)- addAsLink
Logical. If
TRUE, creates a link in the inventory for provenance tracking. UseimproveClean()at workflow end to clean up links- caption
Custom caption text. If empty, defaults to entityID and lastModified timestamp
- description
Custom description text. If empty, defaults to filename
- ...
Additional arguments passed to
readLines()
Value
A list object (descriptor) with the following components:
data: Character string containing the complete file contents with lines collapsed using newline (\n) separatorsdataType: Character string set to "Text"path: Character string with local file pathcaption: Character string with caption textdescription: Character string with description textAdditional metadata fields from the resource descriptor
Details
The function reads all lines from the text file using readLines() and collapses
them into a single character string. The returned descriptor integrates with
improve's provenance tracking when addAsLink = TRUE. Access the text content
via result$data.
Examples
if (FALSE) { # \dontrun{
# Load text file from current step
text_desc <- getTextString("report_text.txt")
content <- text_desc$data # Extract text string
# Load file with custom metadata
script_desc <- getTextString(
"scripts/analysis.R",
caption = "Main Analysis Script",
description = "Primary statistical analysis code"
)
} # }