Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadStat api updates #65

hadley opened this issue Apr 17, 2015 · 0 comments

ReadStat api updates #65

hadley opened this issue Apr 17, 2015 · 0 comments


Copy link

@hadley hadley commented Apr 17, 2015

Variable handlers now take 4 arguments instead of 7, using the readstat_variable_t to wrap the values that were previously passed separately. New callback signature:

typedef int (*readstat_variable_handler)(int index, readstat_variable_t *variable,
const char *val_labels, void *ctx);

You can access the previous values with new accessor functions:

const char *readstat_variable_get_name(readstat_variable_t *variable);
const char *readstat_variable_get_label(readstat_variable_t *variable);
const char *readstat_variable_get_format(readstat_variable_t *variable);
readstat_types_t readstat_variable_get_type(readstat_variable_t *variable);

In the future I'd like to stuff the value labels into the variable argument, and eliminate the value labels handler altogether, but this is not implemented.

The motivation here was adding support for missing value definitions. To access the definitions with SPSS files inside the variable handler, you can use:

int readstat_variable_get_missing_ranges_count(readstat_variable_t *variable);
readstat_value_t readstat_variable_get_missing_range_lo(readstat_variable_t *variable, int i);
readstat_value_t readstat_variable_get_missing_range_hi(readstat_variable_t *variable, int i);

"lo" and "hi" represent the lower and upper bounds of the missing range -- if lo == hi, then it's a single missing value rather than a contiguous range.

readstat_value_is_missing is now supplemented with two more functions to distinguish system-missing (e.g. NaN values) from values that are considered missing on account of the missing value definitions:

int readstat_value_is_system_missing(readstat_value_t value);
int readstat_value_is_considered_missing(readstat_value_t value);

But you can continue to use readstat_value_is_missing, which is just an OR of those two functions.

The underlying representation of readstat_value_t is no longer a pointer to a primitive value; instead, it's a struct + union that includes missingness information as well as the value type. As an added convenience, readstat_double_value etc. will do appropriate casting from other numeric types. Your existing accessor code should continue to work, but you might be able to simplify it with the new automatic casting.

@hadley hadley closed this in cd623bb Jun 19, 2015
@lock lock bot locked and limited conversation to collaborators Jun 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant