In one call, downloads one director's report from the SIU web site with
siufetch() and parses it with siuprs().
It is meant for loops over many
report ids: a report that
cannot be retrieved gives NULL and a message instead of stopping
the loop.
Usage
siufprs(drid, lang = c("en", "fr"))Value
A named character vector of parsed fields, as from
siuprs(), or NULL when the
fetch fails.
Details
The arguments are checked before any network use, so a bad id or
language fails at once. The report is downloaded to a temporary file,
which is deleted on exit. Any error from the download (network failure,
an HTTP error, no report at that id) is caught and turned into a message
of the form "bricklayer: could not fetch SIU report <drid>: <reason>"
and a NULL return. Errors from parsing are not caught.
Errors: drid that is not one positive whole number;
lang other than "en" or "fr".
Examples
# argument errors come before any network use
try(siufprs("abc"))
#> Error : `drid` must be one positive report number (the drid in the SIU report URL)
try(siufprs(648, lang = "de"))
#> Error : siufprs: `lang` must be one of "en", "fr", not "de"
if (FALSE) { # interactive()
# needs the network: downloads report 648 from the SIU site
f <- siufprs(648)
if (!is.null(f)) f[["police_service"]]
fr <- siufprs(648, lang = "fr")
}
