Update multiple Klass codes to a desired date.
update_klass(
codes,
dates = NA,
classification = NULL,
date = NULL,
graph = klass_graph(classification, date),
output = "code",
report = FALSE,
combine = TRUE
)
If output = "code"
, a vector of length length(codes)
containing either a code if the update is successful or NA
if the
code has been split. If combine = FALSE
, a code being combined with
another code will also return NA
.
If output == TRUE
, a list of length length(codes)
containing
data.frame
s detailing the codes visited through the node search. The
tables have the following columns.
---
If report == TRUE
and length(output) > 1 | TRUE
, the result
will be a list of data.frame
s with number of rows equal to the
number of codes in the sequence of changes between the input codes and
output codes. The columns in the data.frame
s are specified with
output
.
If report == TRUE
and length(output) == 1
, the result will be
a list of character vectors with length equal to the number of codes in the
sequence of changes between the input code and output code. The contents of
the character vectors is specified with output
.
If report == FALSE
and length(output) > 1 | TRUE
the result
will be a list of data.frame
s with one row representing the last
code in the change sequence and columns specified by output
. If a
code has been split, the result will be NA
. If combine ==
FALSE
and a code is the result of a combination of codes, the result will
be NA
.
If report == FALSE
and length(output) == 1
, the result will
be a character vector containing information about the updated codes
specified by output
. If a code has been split, the result will be
NA
. If combine == FALSE
and a code is the result of a
combination of codes, the result will be NA
.
Codes to be updated.
Optional. Can be used to specify what date each of the codes was
valid in. Supply a character vector of either length 1 to specify the same
valid date for all codes, or of the same length as codes
to specify
valid dates for each code. The character vector(s) should have a format
coercible by as.Date
, e.g. YYYY-MM-DD
. The
function will return an error if a code was not valid at the specified
date.
The ID of the desired classification.
Optional. Can be used to specify the date the codes should be
updated to, e.g. if you have codes that are valid in year T
, but
want to change the codes to the corresponding version in year T-1
.
If unspecified (the default), the function will update codes to the most
recent version.
Optional. A graph object generated by klass_graph
.
If you're making multiple calls to [update_klass], you can save some time by
generating the graph beforehand and reusing it for each call to
[update_klass] with this parameter. If providing the graph directly, you do
not need to provide the classification
and date
parameters.
Either a character vector, containing one or more of the items
in the list below, or TRUE
to include all columns.
"code"
The Klass code.
"name"
The Klass name.
"validFrom"
The date that the code is valid from.
"validTo"
The date that the code is valid to.
"split"
Logical: Does the code split into two or more codes?
"combined"
Logical: Does two or more codes become this code?
"nextCode"
If split == FALSE
, gives the code this code changed into. NA
otherwise.
TRUE
or FALSE
. See the return section.
TRUE
or FALSE
. See the return section.
library(klassR)
codes <- get_klass(131, date = "2020-01-01")[["code"]]
if (FALSE) {
updated_codes <- update_klass(codes,
dates = "2020-01-01",
classification = 131
)
}
Run the code above in your browser using DataLab