Use this tag for questions related to the `haven` package for the R programming language. The `haven` package "enables R to read and write various data formats used by other statistical packages". For more information on the `haven` package see the [package website](https://haven.tidyverse.org/index.html).
Questions tagged [r-haven]
159 questions
0
votes
0 answers
How to deal with "ERROR: Can't combine" when using Stata data read into R with haven?
I am having trouble working with Stata data that I have read into R. The data seems to be read in okay, and then is a tbl data.frame haven data class. However, when I try to do things like subset it, I get an error. Can anybody help?
data <-…

Nick Olczak
- 305
- 3
- 14
0
votes
1 answer
Run a function across columns without stripping Labelled attributes
I have a large number of SPSS files, and I need to generate random data that looks like the data that is in the file.
When I read in the SPSS files (using haven's read_sav), they come in with variable and value labels (from labelled), and I would…

seehuus
- 103
- 1
- 6
0
votes
0 answers
Error: basic_string::_M_construct null not valid when using haven::read_sav() - tidyverse question
I have a problem when trying to read in a SPSS-file with haven::read_sav(). Since my knowledge of C++ is very limited and this seems to (maybe?) be an issue with C++ I'm a bit lost right now how to solve this problem or even give a good description…

jakoberr
- 43
- 4
0
votes
0 answers
Do SAS formats transfer to Rstudio?
I have a dataset that I have transferred from SAS to Rstudio via the haven package.
But when I inspect my dataset in R, I can see that some of the formatted variables are indeed still formatted, while some of the variables are shown as the 'raw'…

Lærke Kjær
- 21
- 3
0
votes
1 answer
How to write unique variable names with write_sav
I'm trying to write an SPSS file with some haven_labelled variables and factors that are created from that variable. It's just convenient for me and my use case to use nearly identical variable names. I've used all lower case for the haven_labelled…

spindoctor
- 1,719
- 1
- 18
- 42
0
votes
0 answers
Haven not working for exporting SAS. SAS7bdat package not compatible with R version
I've been trying to import an SAS file with both Haven and sas7bdat. With the Haven package it gives me an error saying: "Failed to parse C:/Users/mtmol/Desktop/Wk1_Data.sas7bdat: Invalid file, or file has unsupported features." yet, I know there is…
0
votes
0 answers
Write Data From .SAV to .CSV (header data missing)
when I write my sav file into csv (using library(haven), read_sav and write.csv), it can export to csv file properly, but some of the text in my header is missing. For example, each header has a question number with some subtext describing the…

sky0215
- 29
- 5
0
votes
1 answer
Is there a way to designate a specific Haven R label as NA?
This question is for the Haven package in R.
Suppose that I have a variable with the following labels:
1 (Agree)
2 (Neutral)
3 (Disagree)
5 (Did not respond)
But the SPSS .sav file I imported into R using haven didn't designate 5 as the missing…

ssjjaca
- 219
- 1
- 6
0
votes
2 answers
ggplot accessing data labels rather than data values
I've imported some SPSS data into R, the data is labelled and I want to plot the label names, rather than the values. I've tried the below, but it prints the values
library(labelled)
library(tidyverse)
cols <- c("White", "Red", "Black", "Green",…

pluke
- 3,832
- 5
- 45
- 68
0
votes
1 answer
R - Haven - SPSS (.sav): Iterate over all columns and replace name and label of columns
for a project I needed to merge an Excel and an SPSS file with R.
Not sure if this was my best idea. I got the merge done, however in the process
I had to use the attribute(col)$label as the name in order to work.
My final merged data.frame has thus…

Björn
- 1,610
- 2
- 17
- 37
0
votes
1 answer
stripping value labels from imported SPSS `.sav` data
In haven docs, I've seen examples of how zap_labels() will strip value labels from variables. In each case in the docs, the variable used in the example was created using an R assignment operator (<-) to directly create a vector (e.g. image below,…

thanks_in_advance
- 2,603
- 6
- 28
- 44
0
votes
1 answer
Error: Problem with `mutate()` input x `labels` must be unique
I am trying to recode some labelled variables to a 0 to 1 scale in the following fashion. When I try to calculate the mean of the two variables using c_across() I get this odd error Error: Problem with mutate() input market_liberalism. x labels must…

spindoctor
- 1,719
- 1
- 18
- 42
0
votes
1 answer
correctly treating NA values in SPSS .sav file imported into R using R's Haven package
My platform is Windows 10
The data in my .sav file looks like this (the screenshots are from PSPP not SPSS):
Data View:
Variable View:
I'm using haven to import the .sav file into R:
library("tidyverse")
library("haven")
haven commands (my .sav…

thanks_in_advance
- 2,603
- 6
- 28
- 44
0
votes
1 answer
Combine two excel data sets with labels and values to one labeled SPSS
I have two excel files that originally came from an SPSS dataset. One has values and the other one holds the labels. Is there an easy way to combine both sources and save it as a labeled SPSS dataset?
The input looks like that:
ds1 <-…

oriloc
- 49
- 1
- 4
0
votes
0 answers
On new computer, read_spss() is suddenly leading all of my code to result in: Can't combine `..1` and `..2`
in R, read_spss() was working perfectly for importing a data set, but I just transferred all of the code over to my new MacBook, and now none of the code works -- it all generates this error message:
Error: Can't combine ..1 and ..2 .
Does anyone…

EricS
- 1
- 1