-
Notifications
You must be signed in to change notification settings - Fork 117
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
Fix issue with read_dta crashing R #619
Conversation
Woops, missed one, also fixes #594 |
Yeah, lets make it |
No worries, done! I'm not much of a C person so it feels super hacky, but it works 😛 |
src/DfReader.cpp
Outdated
|
||
if (readstat_value_is_tagged_missing(value)) { | ||
col[obs_index] = NA_STRING; | ||
} else if (!user_na_ && readstat_value_is_defined_missing(value, variable)) { | ||
col[obs_index] = NA_STRING; | ||
} else if (readstat_value_is_system_missing(value)) { | ||
col[obs_index] = NA_STRING; | ||
} else if (str_value == NULL) { | ||
const char empty_string[1] = { '\0' }; | ||
col[obs_index] = cpp11::r_string(empty_string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just do cpp11::r_string("")
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha yep! Too much time in R treating "" and '' as equivalent 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thanks for working on this! Will prepare a release next week some time. |
The updates for cpp11 reintroduced the bug in #79 when read_dta is used on a file that has empty values in an StrL variable (#600, #608). This PR restores the old behaviour and returns an NA for these observations.
@hadley, the StrL section of the dta spec says that a NULL (i.e. no StrL address) should be interpreted as the empty string
""
rather than a missing value, soNA_STRING
might not actually be the most appropriate value here (although it would be consistent with previous versions of haven).What do you think?