Learn R Programming

arealDB (version 0.3.9)

setVariables: Set index and translation tables

Description

Use a pre-compiled table to create an index and/or translation table for the target variables of an areal database.

Usage

setVariables(
  input = NULL,
  variable = NULL,
  type = "both",
  pid = NULL,
  origin = NULL,
  target = NULL
)

Arguments

input

[tibble(1)] a possibly already existing table based on which the output should be constructed; see details.

variable

[character(1)] name of the variable and thus of the output file(s).

type

[character(1)] the type of table to create, either an index ("id"), a translation table ("tt") or "both" (default).

pid

[character(1)] column in input that contains the primary ID for the index table. If this is not given, an ID name is created as paste0(str_sub(variable, 1, 3), "ID")

origin

[character(1)] column in input that contains terms that shall be translated.

target

[character(1)] column in input that contains the standardised terms.

Value

No return value, called for the side effect of writing a table to the project root directory with name paste0(type, "_", variable, ".csv").

Details

This is the second function that is run in a project, as it creates index and translation tables for the target variables that shall be stored in an areal database.

  • An index table relates an ID (given in pid) to the variable terms (given in target) and potentially to ancillary information. Such tables should be compiled before a project is started and should contain a clear set of values per variable (which will be used as standard vocabulary).

  • A translation table relates terms in foreign languages (given in origin) to terms in the target language (given in target). A "foreign language" does not only have to be another language per se, but could also be a vocabulary with a different set of terms that carry the same semantic meaning as the target terms. If target does not exist, the terms are simply registered as "original" to be used for fuzzy matching.

Examples

Run this code
# NOT RUN {
library(readr)
inPath <- system.file("test_datasets", package = "arealDB", mustWork = TRUE)

# start the example database
makeExampleDB(until = "setPath")

# create index from an already existing table
comm <- read_csv(file = paste0(inPath, "/id_commodities.csv"),
                 col_types = "iccc")
setVariables(input = comm, variable = "commodities",
             pid = "faoID", target = "simpleName")
# }

Run the code above in your browser using DataLab