Use user width when writing long string value label records in SAV writer #353
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The SAV writer functions that emit value labels for long string variables assume that the variable storage width is wider than the value label keys, but this is not checked during file writing so ReadStat can produce invalid files that don't throw an error on write (see tidyverse/haven#537).
This PR initially added a check for this during writing, including a minor update to the test suite to support tests with a manually specified storage width. While I was testing I noticed that PSPP isn't happy with using the storage width if it is wider than the user width and you get an error like:
I've updated the long string value writer to use the user width instead of storage width, and confirmed files now load successfully in PSPP (and still roundtrip successfully in ReadStat).
I think this fixes #323, tidyverse/haven#550 and Roche/pyreadstat#264.