adjust: changes the elements of basic blocks used by rejustify API

Description Usage Arguments Value Examples

View source: R/adjust.R

Description

The purpose of the function is to provide a possibly seamless way of adjusting blocks used in communication with rejustify API, in particular with the fill endpoint. The blocks include: data structure (structure), default values (default) and matching keys (kets). Items may only be deleted for specific matching dimensions proposed by keys, for the two other blocks it is possible only to change the relevant values.

Upon changes in structure, the corresponding p_class or p_data will be set to -1. This is the way to inform API that the original structure has changed and, if learn option is enabled, the new values will be used to train the algorithms in the back end. If learn is disabled, information will not be stored by the API but the changes will be recognized in the current API call.

Usage

1
adjust(block, column = NULL, id = NULL, items = NULL)

Arguments

block

A data structure to be changed. Currently supported structures include structure, default and keys.

column

The data column (or raw in case of horizontal datasets) to be adjusted. Vector values are supported.

id

The identifier of the specific element to be changed. Currently it should be only used in structure with multi-line headers (see analyze for details).

items

Specific items to be changed with the new values to be assigned. If the values are set to NA, NULL or "", the specific item will be removed from the block (only for keys). Items may be multi-valued.

Value

adjusted structure of the df data set

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#API setup
setCurl()

#register token/email
register(token = "YOUR_TOKEN", email = "YOUR_EMAIL")

#sample data set
df <- data.frame(year = c("2009", "2010", "2011"),
                 country = c("Poland", "Poland", "Poland"),
                 `gross domestic product` = c(NA, NA, NA),
                 check.names = FALSE, stringsAsFactors = FALSE)

#endpoint analyze
st <- analyze(df)

#adjust structures
st <- adjust(st, id = 2, items = list('feature' = 'country'))
st <- adjust(st, column = 3, items = list('provider' = 'IMF', 'table' = 'WEO'))

#endpoint fill
df1 <- fill(df, st)

#adjust default values
default <- adjust(df1$default, column = 3, items = list('Time Dimension' = '2013') )

#adjust keys
keys <- adjust(df1$keys, column = 3, items = list('id.x' = c(3,1,2) , 'id.y' = c(1,2,3) ) )
keys <- adjust(df1$keys, column = 3, items = list('id.x' = 3 , 'id.y' = NA ) )

rejustify/r-package documentation built on Nov. 7, 2021, 2:10 p.m.