Skip to contents

Resolve String(s) Using a Dictionary

Usage

resolve(x, ...)

Arguments

x

vector of character to be resolved or a list of which all elements will be resolved using itself as a "dictionary". A dictionary is a list of key = value pairs defining string replacements.

...

Unnamed arguments are treated as (further) dictionaries. These are merged first to one dictionary before merging further (named) key = value pairs.

Examples

file <- system.file("extdata", "dictionary.txt", package = "kwb.utils")

dictionary <- readDictionary(file)

# Resolve the dictionary
resolve(dictionary)
#> $dir.out
#> [1] "/root/example_project/out"
#> 
#> $dir.project
#> [1] "/root/example_project"
#> 
#> $dir.root
#> [1] "/root"
#> 
#> $equation
#> [1] "a = b + c"
#> 
#> $file.out
#> [1] "/root/example_project/out/example_file.<extension>"
#> 
#> $project
#> [1] "example_project"
#> 

# Resolve the dictionary by setting an undefined placeholder
resolve(dictionary, extension = "pdf")
#> $dir.out
#> [1] "/root/example_project/out"
#> 
#> $dir.project
#> [1] "/root/example_project"
#> 
#> $dir.root
#> [1] "/root"
#> 
#> $equation
#> [1] "a = b + c"
#> 
#> $file.out
#> [1] "/root/example_project/out/example_file.pdf"
#> 
#> $project
#> [1] "example_project"
#> 
  
# Resolve a string
resolve("dir.project", dictionary)
#> [1] "/root/example_project"

# Set a placeholder "on-the-fly"
resolve("file.out", dictionary, extension = "pdf")
#> [1] "/root/example_project/out/example_file.pdf"

# Override a placeholder "on-the-fly"
resolve("dir.project", dictionary, project = "new_project")
#> [1] "/root/new_project"

# Resolve a vector of strings
resolve(c("dir.root", "dir.project"), dictionary, project = "vector")
#> [1] "/root"        "/root/vector"