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

SPSS system missings read as NaN #223

Closed
wepelham3 opened this Issue Sep 30, 2016 · 9 comments

Comments

Projects
None yet
7 participants
@wepelham3
Copy link

wepelham3 commented Sep 30, 2016

After installing the v1.0.0 update I noticed a bunch of NaNs in datasets I have been importing to R from SPSS using read_sav().

It appears that the . or system missing values in my .sav files are now being read into R as NaN rather than NA.

Here is a dataset with just one variable to illustrate the issue.

This variable has 12 missing values in the .sav file, and when imported with haven v0.2.0 we see 12 NAs in R. Then when imported with haven v1.0.0 we see 12 NaNs in R.

Here is code to reproduce the issue with that dataset:

remove.packages("haven")

# with v0.2.0 the 12 missing values are read in as NA
devtools::install_version("haven", version = "0.2.0", repos = "http://cran.us.r-project.org")
data <- haven::read_sav("data.sav")
table(data$var1, useNA = "always")

remove.packages("haven")

# with v1.0.0 the 12 missing values are read in as NaN
install.packages("haven") # v1.0.0
data <- haven::read_sav("data.sav")
table(data$var1, useNA = "always")

@hadley hadley closed this in fb4ccfc Oct 30, 2016

@hadley hadley reopened this Oct 30, 2016

@hadley hadley added bug reprex labels Jan 25, 2017

@hadley hadley changed the title after updating to v1.0.0, system missing values in .sav file are now read into R as "NaN" SPSS system missings read as NaN Jan 25, 2017

@pkq

This comment has been minimized.

Copy link
Contributor

pkq commented Jan 26, 2017

I think this should work. I had some trouble getting the install/loading sequence automated, but it passed reprex, so I think it gives you what you need. Let me know if you have any questions!

df <- tibble::tibble(x = c(1, 2, NA, 4, NA))
tempfile <- tempfile(fileext = ".sav")
write_sav(df, tempfile)

read_sav(tempfile)$x

@hadley hadley removed the reprex label Jan 26, 2017

@pkq

This comment has been minimized.

Copy link
Contributor

pkq commented Jan 26, 2017

Much appreciated!

@hadley hadley closed this in 9fa82af Jan 27, 2017

@pkq

This comment has been minimized.

Copy link
Contributor

pkq commented Jan 27, 2017

Awesome, thanks @hadley!

@Keniajin

This comment has been minimized.

Copy link

Keniajin commented Feb 22, 2017

realised the same issue with read_dta()

@eivindhammers

This comment has been minimized.

Copy link

eivindhammers commented Mar 9, 2017

@tomhopper

This comment has been minimized.

Copy link

tomhopper commented May 26, 2017

@Keniajin +1

See attached file for example data set.

unloadNamespace("haven")
devtools::dev_mode(on = TRUE)
devtools::install_version("haven", version = "0.2.0", repos = "http://cran.us.r-project.org")
library(haven)
packageVersion("haven")
# returns '0.2.0'
states_df <- read_dta(path = "dataSets/states.dta")
states_df
# Shows NA in row 9 and elsewhere that should be NA
devtools::dev_mode(on = FALSE)
unloadNamespace("haven")

library(haven)
packageVersion("haven")
# returns '1.0.0'
states_df <- read_dta(file = "dataSets/states.dta")
states_df
# Shows NaN in row 9 and elsewhere that should be NA
unloadNamespace("haven")

states.dta.zip

@borisma

This comment has been minimized.

Copy link

borisma commented Jul 1, 2017

Hello! I would like to ask when the haven CRAN version will be updated? We are using haven for introductory psychology stats and first year students do not usually install from github. We can't use haven properly as long as the CRAN version imports missings as NaN. Thanks!

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jul 7, 2017

I'll add a release to my to do list. Looking at the news, I think it should be straightforward so will hopefully happen next week.

@borisma

This comment has been minimized.

Copy link

borisma commented Jul 31, 2017

Thanks very much!

@lock lock bot locked and limited conversation to collaborators Jun 26, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.