Skip to content
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

read_sav fails on zipped files when using col_select #720

Open
jokroese opened this issue May 3, 2023 · 0 comments
Open

read_sav fails on zipped files when using col_select #720

jokroese opened this issue May 3, 2023 · 0 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@jokroese
Copy link

jokroese commented May 3, 2023

Problem

When working with large .sav files, I want to both zip them (to reduce their storage space) and read them in with col_select (to reduce their space in memory). Unfortunately, when doing both (reading a zipped file with col_select), haven::read_sav breaks.

Reprex

data <- tibble::tibble(x = 1:5, y = letters[1:5])

haven::write_sav(data, path="test.sav")

zip("test.zip", "test.sav")

# this works
test_works <- haven::read_sav(
  unz("test.zip", "test.sav")
)

# but this fails
test_fails <- haven::read_sav(
  unz("test.zip", "test.sav"),
  col_select = c(x)
)
# Error in isOpen(con) : invalid connection

Workaround

There's a simple workaround:

unz("test.zip", "test.sav")
haven::read_sav(
  "test.sav",
  col_select = c(x)
)
file.remove("test.sav")

but I do this often enough that I'd appreciate it working natively in haven without a function implementing the above workaround.

@gorcha gorcha added the bug an unexpected problem or unintended behavior label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants