Skip to content

Commit

Permalink
Fix issue with read_dta crashing R (#619)
Browse files Browse the repository at this point in the history
And empty string instead of NA string for empty StrL variables

Fixes #594. Fixes #600. Fixes #608.
  • Loading branch information
gorcha authored Jul 26, 2021
1 parent 260d2c2 commit 078dd6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# haven (development version)

* Fix issue with `read_dta()` crashing R when StrL variables with missing values
were present (@gorcha, #594, #600, #608).

* The buglet fixed in 2.4.1 when combining `labelled()` with identical labels
has been fixed in `labelled_spss()` (@gorcha, #599).

Expand Down
5 changes: 4 additions & 1 deletion src/DfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,18 @@ class DfReader {
case READSTAT_TYPE_STRING:
{
cpp11::writable::strings col(output_[var_index]);
const char* str_value = readstat_string_value(value);

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) {
col[obs_index] = cpp11::r_string("");
} else {
col[obs_index] = cpp11::r_string(readstat_string_value(value));
col[obs_index] = cpp11::r_string(str_value);
}
break;
}
Expand Down

0 comments on commit 078dd6b

Please sign in to comment.