Skip to content

Commit

Permalink
Fix issue with read_dta crashing R (tidyverse#600, tidyverse#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
gorcha committed Jul 25, 2021
1 parent dbd65a3 commit 7380bc8
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, #600, #608).

# haven 2.4.1

* Fix buglet when combining `labelled()` with identical labels.
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] = NA_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 7380bc8

Please sign in to comment.