vectorSCB: Vectorise a call to SCB

Description Usage Arguments Value See Also Examples

View source: R/vectorSCB.r

Description

This function provides vectorisation of the SCB function – it is effectively equivalent to just doing it yourself with an sapply call, but it is considerably faster, since it doesn't have to run query() once per level you're vectorising over. It is called precisely like SCB() for the query, but its other parameters are different. The central one is vectorColumn which should be set to the name of a column. The function then looks at whether you provided a list of values for that column: If you did, the function runs your query on each of those values, otherwise, if you omitted that column, it looks up what all of its possible values are, and vectorises over those. The verbose and failIfUnable parameters still exist, with the same effect, but collisionHandlingMode is not supported.

Usage

1
2
3
4
5
6
7
vectorSCB(
  vectorColumn,
  verbose = FALSE,
  forceTable = NA_character_,
  failIfUnable = FALSE,
  ...
)

Arguments

vectorColumn

Which column should be vectorised over. This argument should not be quoted, just write it straight up. See examples.

verbose

Causes some extra messages to be printed explaining what is happening. If you are getting unexpected results, try setting this to TRUE first.

forceTable

Directs the query to a specific table, in case your query does not uniquely determine a table.

failIfUnable

If the query cannot be handled by our tables, should we throw an error, or just a warning and return NA? TRUE gives errors, FALSE gives warnings.

...

Your query, see documentation of SCB() for syntax for this.

Value

A named vector whose elements are results from SCB() and names are the level of the column we vectorised over

See Also

SCB

Examples

1
2
3
4
5
6
7
8
# How much forest is there in each municipality in Sweden?:
vectorSCB(LandUseType = "Total forest", vectorColumn = Municipality)
# How much land is used for each type of use in Ludvika municipality?
vectorSCB(Municipality = "Ludvika", vectorColumn = LandUseType)
# In order to use a column whose name is stored in a variable, use !! like this:
# (!! is provided by the library rlang.)
columnToVector <- "Municipality"
vectorSCB(Gender = "Male", forceTable = "AgeGender", vectorColumn = !!columnToVector)

vagdur/SCBHandlerPlotter documentation built on March 28, 2021, 11:35 p.m.