chk_nitems | R Documentation |
These functions are designed to used within custom scoring
functions to help check the arguments passed to those functions. Typically,
these argument checkers will be used within the body of a custom scoring
function before calling the scoreScale
function to handle the
bulk of the work. See Details.
chk_nitems
checks if dfItems
contains the correct
number of items (nitems
), and chkstop_nitems
returns an
error message if this condition is not met.
chk_values
checks if all of the item values in dfItems
are in the set of possible values given to the values
argument,
and chkstop_values
returns an error message if this condition is
not met.
chk_nitems(dfItems, nitems)
chkstop_nitems(dfItems, nitems)
chk_values(dfItems, values)
chkstop_values(dfItems, values)
dfItems |
A data frame with only the items to be scored. |
nitems |
The number of items on the scale to be scored. |
values |
A vector of all of the possible values that the items can take. |
Functions with prefix chk_
simply check whether their
argument values meet a condition and return TRUE
or FALSE
.
Functions with the prefix chkstop_
check the arguments and, if
FALSE
, stop execution and display an error message to help the user
pinpoint the problem.
The scoreScale
function is a general, all-purpose tool that
can be used to score a scale regardless of the number or values of items on
the scale. Because of this, however, it does not check that the user has
given it the correct number of items, and it does not check that those item
values are all within the range possible for that scale. Therefore,
whenever scoreScale
is used to write a function to score a
specific instrument (presumably with a known number of items and item
values), the programmer should run some additional checks on the arguments
that are not already built-in to scoreScale
.
Functions with prefix chk_
return TRUE
if the arguments
pass the argument checks, or FALSE
if the arguments
fail the checks. Functions with the prefix chkstop_
print
an error message and stop the execution of the function in which they are
embedded.
Use with caution! These functions work, but they might be deprecated in future updates of the package. I am hoping to come up with a more streamlined, user-friendly system for checking arguments and input values. Until then, these functions get the job done, but not as gracefully as I would like.
itemBad <- c(0, 1, 2, 3, 10)
itemGood <- c(0, 1, 2, 3, 0)
dfBad <- data.frame(itemBad, itemGood)
dfGood <- data.frame(itemGood, itemGood)
chk_nitems(dfBad, 1)
chk_nitems(dfGood, 2)
chk_values(dfBad, 0:3)
chk_values(dfGood, 0:3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.