List all known metadata fields in the SewerRat database.

listFields(
  url,
  pattern = NULL,
  count = FALSE,
  number = 1000,
  on.truncation = c("message", "warning", "none")
)

Arguments

url

String containing the URL to the SewerRat REST API.

pattern

String specifying a pattern for filtering fields, using the usual * and ? wildcards. Only fields matching to the pattern will be returned. If NULL, no filtering is performed.

count

Logical scalar indicating whether to count the number of metadata files associated with each field.

number

Integer specifying the maximum number of results to return. This can also be Inf to return all results.

on.truncation

String specifying what to do when the number of results exceeds number. Either "warning", "message", or "none".

Value

List of named lists, where each inner list corresponds to a field and contains:

  • field, string containing the field.

  • count, integer scalar specifying the number of files associated with the field. This is only present if count=TRUE in the arguments.

Examples

# Starting up an example SewerRat service:
info <- startSewerRat()

# Mocking up a directory of stuff to query.
mydir <- tempfile()
dir.create(mydir)
write(file=file.path(mydir, "metadata.json"), '{ "first": "Aaron", "last": "Lun" }')
dir.create(file.path(mydir, "diet"))
write(file=file.path(mydir, "diet", "metadata.json"), 
   '{ "meal": "lunch", "ingredients": "water" }')

# Registering it:
register(mydir, "metadata.json", url=info$url)

# Pulling out all the fields.
listFields(info$url)
#> [[1]]
#> [[1]]$field
#> [1] "first"
#> 
#> 
#> [[2]]
#> [[2]]$field
#> [1] "foo"
#> 
#> 
#> [[3]]
#> [[3]]$field
#> [1] "ingredients"
#> 
#> 
#> [[4]]
#> [[4]]$field
#> [1] "last"
#> 
#> 
#> [[5]]
#> [[5]]$field
#> [1] "meal"
#> 
#> 
listFields(info$url, pattern="fir*")
#> [[1]]
#> [[1]]$field
#> [1] "first"
#> 
#> 
listFields(info$url, count=TRUE)
#> [[1]]
#> [[1]]$field
#> [1] "first"
#> 
#> [[1]]$count
#> [1] 1
#> 
#> 
#> [[2]]
#> [[2]]$field
#> [1] "ingredients"
#> 
#> [[2]]$count
#> [1] 1
#> 
#> 
#> [[3]]
#> [[3]]$field
#> [1] "last"
#> 
#> [[3]]$count
#> [1] 1
#> 
#> 
#> [[4]]
#> [[4]]$field
#> [1] "meal"
#> 
#> [[4]]$count
#> [1] 1
#> 
#>