Parse Valve's VDF or KeyValues format. VDF files are similar to JSON and are used to store hierarchical metadata on resources, scripts, materials, etc. Request functions such as request_webapi allow VDF as a response format. For most use cases in data analysis, the VDF format should not have any advantages over JSON.

parse_vdf(x, check_types = TRUE)

Arguments

x

A string containing a KeyValues or VDF body.

check_types

Whether to automatically detect types and try to convert them to R objects. By default, the KeyValues format only knows strings.

Details

The parsing algorithm follows the official documentation of the Valve developer community wiki. The basic structure knows three control characters: {, }, and \". Double quotes signify a key or a value. A key can either be followed by a value or by a curly bracket indicating the beginning of a new nesting level. Accordingly, a key can hold either a length-1 value or a named list.

Lines beginning with # are interpreted as macros and are omitted. Comments (beginning with // or /*) end a line and remove everything up to the end of the line. Expressions in square brackets are omitted (based on recommendations from here).

Examples

# example vdf
vdf <- '"someresource" [$WIN]
{
  "foo" "bar" // Some comment
  "odd" "record" [$ODD]
  "someotherresource"
  {
    "baz" "tar"
  }
}'

parse_vdf(vdf)
#> $someresource
#> $someresource$foo
#> [1] "bar"
#> 
#> $someresource$odd
#> [1] "record"
#> 
#> $someresource$someotherresource
#> $someresource$someotherresource$baz
#> [1] "tar"
#> 
#> 
#> 

if (FALSE) { # \dontrun{
# vdf from web API
vdf <- request_webapi(
  api = public_api(),
  interface = "IStoreService",
  method = "GetTagList",
  version = "v1",
  params = list(language = "english"),
  format = "vdf"
)

parse_vdf(vdf)
} # }