List available tokens in the SewerRat database.

listTokens(
  url,
  pattern = NULL,
  field = 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 tokens, using the usual * and ? wildcards. Only tokens matching to the pattern will be returned. If NULL, no filtering is performed.

field

String specifying a metadata property field for filtering tokens. Only tokens found in the specified field will be returned. If NULL, no filtering is performed.

count

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

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 token and contains:

  • token, string containing the token.

  • count, integer scalar specifying the number of files associated with the token. 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 tokens.
listTokens(info$url)
#> [[1]]
#> [[1]]$token
#> [1] "aaron"
#> 
#> 
#> [[2]]
#> [[2]]$token
#> [1] "bar"
#> 
#> 
#> [[3]]
#> [[3]]$token
#> [1] "lun"
#> 
#> 
#> [[4]]
#> [[4]]$token
#> [1] "lunch"
#> 
#> 
#> [[5]]
#> [[5]]$token
#> [1] "water"
#> 
#> 
listTokens(info$url, pattern="lun*")
#> [[1]]
#> [[1]]$token
#> [1] "lun"
#> 
#> 
#> [[2]]
#> [[2]]$token
#> [1] "lunch"
#> 
#> 
listTokens(info$url, field="ingredients")
#> [[1]]
#> [[1]]$token
#> [1] "water"
#> 
#> 
#> [[2]]
#> [[2]]$token
#> [1] "water"
#> 
#> 
#> [[3]]
#> [[3]]$token
#> [1] "water"
#> 
#> 
#> [[4]]
#> [[4]]$token
#> [1] "water"
#> 
#> 
listTokens(info$url, count=TRUE)
#> [[1]]
#> [[1]]$token
#> [1] "aaron"
#> 
#> [[1]]$count
#> [1] 4
#> 
#> 
#> [[2]]
#> [[2]]$token
#> [1] "lun"
#> 
#> [[2]]$count
#> [1] 4
#> 
#> 
#> [[3]]
#> [[3]]$token
#> [1] "lunch"
#> 
#> [[3]]$count
#> [1] 4
#> 
#> 
#> [[4]]
#> [[4]]$token
#> [1] "water"
#> 
#> [[4]]$count
#> [1] 4
#> 
#>