Skip to content

Commit

Permalink
Use old-style SPSS compression by default for .sav (SPSS) files, sinc…
Browse files Browse the repository at this point in the history
…e almost nobody uses the inefficient uncompressed format. The newer ZCompressed format (compress=TRUE) is even better, but is much less used and less supported by third-party tools. (#544)

Co-authored-by: numbers <numbers@dockerhost>
  • Loading branch information
oliverbock and numbers authored Apr 9, 2021
1 parent 2dc8ec1 commit 3130d51
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* Updated to ReadStat 1.1.5. Most importantly this includes support for
SAS binary compression.

* `write_sav(..., compress=FALSE)` now uses SPSS Bytecode compression instead
of the rarely-used uncompressed mode. `compress=TRUE` continues to use the new
(and not universally supported, but more compact) ZLIB format. (@oliverbock, #544)

# haven 2.3.1

* Add missing methods so `median()`, `quantile()` and `summary()` work
Expand Down
2 changes: 1 addition & 1 deletion R/haven.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ read_por <- function(file, user_na = FALSE, col_select = NULL, skip = 0, n_max =
#' @export
#' @rdname read_spss
#' @param compress If `TRUE`, will compress the file, resulting in a `.zsav`
#' file.
#' file. Otherwise the `.sav` file will be bytecode compressed.
write_sav <- function(data, path, compress = FALSE) {
validate_sav(data)
write_sav_(data, normalizePath(path, mustWork = FALSE), compress = compress)
Expand Down
2 changes: 1 addition & 1 deletion man/read_spss.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/DfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ void write_sav_(cpp11::list data, cpp11::strings path, bool compress) {
Writer writer(HAVEN_SAV, data, path);
if (compress)
writer.setCompression(READSTAT_COMPRESS_BINARY);
else
writer.setCompression(READSTAT_COMPRESS_ROWS);
writer.write();
}

Expand Down

0 comments on commit 3130d51

Please sign in to comment.