The `haven` package for `R`
Questions tagged [r-haven]
118 questions
1
vote
0 answers
Labels of a tbl_df dataframe
I have an object of the class "tbl_df", from an imported spss-File (package haven).
I work with an R-Markdown file. When I access a certain variable of my dataframe data$question10, in the console it shows the vector of values (all 1 and 0), but…
![](../../users/profiles/11016300.webp)
Zahra
- 11
- 1
1
vote
1 answer
Exported file from R using `haven` cannot be opened by SAS
When exporting data from R using haven::write_sas(), the resulting sas7bdat file is not recognized (i.e. cannot be loaded) by SAS EG/9.4. Although there are several other packages such as foreign that provide alternative approaches, I was hoping to…
![](../../users/profiles/4481570.webp)
al-obrien
- 1,191
- 7
- 23
1
vote
0 answers
Rmarkdown: Error in knitting the whole report while the individual code chunk is working
So I'm R newbie and reading a .dta file into R at some point in the project.
But when I attempt to knit the whole report into HTML, its giving me an error message at that particular code line.
P.S. Its working fine when I run the chunk related to…
![](../../users/profiles/12268513.webp)
zeeshan haider
- 11
- 1
1
vote
1 answer
Unable to import previously working SAS-formats files using R-package 'haven'
Around a year ago, I used the 'haven'-package to import two .sas7bdat files along with their respective .sas7bcat formats and it worked wonderfully.
For some reason, however, it does not any longer even though all the SAS-files incl. format files…
![](../../users/profiles/7042860.webp)
ChrE
- 13
- 3
1
vote
1 answer
Why does haven::write_dta() inflate file size and can it be changed?
Sometimes I need to convert SPSS files to DTA files. Usually I use Stat/Transfer, but I thought perhaps I could use R to save money.
When I transfer files using the haven package, however, the resulting file size is dramatically higher than when I…
![](../../users/profiles/6539219.webp)
John J.
- 822
- 1
- 8
- 20
1
vote
0 answers
R getting error "`x` and `labels` must be same type"
I'm using R Version 3.6.1 with the following…
![](../../users/profiles/11900596.webp)
Jan
- 87
- 1
- 6
1
vote
0 answers
Loss of labels after conversion of 'haven_labelled' using 'as_factor'
When converting haven_labelled variables to factor variables I (seem to) lose the underlying "labels" (using tidyverse terminology I think...).
# this sets up a factor var x with non-continuous numeric values
library(tidyverse)
library(labelled)
x…
![](../../users/profiles/3745657.webp)
ChrisP
- 119
- 1
- 8
1
vote
1 answer
Saving Stata file with R while preserving labels
I have found a bug in the R haven package where write_dta drops some of the labels when reading it in Stata. I have filed the bug in haven but I really need to find a work around until the bug is fixed. Below is the explanation.
Let's define a…
![](../../users/profiles/3617958.webp)
cimentadaj
- 1,234
- 9
- 20
1
vote
0 answers
Underlying value codes are changed/recoded after exporting data to Stata/SPSS
Good day,
I'm trying to export a labeled dataset to SPSS and Stata. When I open the data in SPSS, the labels export correctly, however, the underlying values are recoded. For example, 0 is recoded to 1. I've tried exporting the data with…
![](../../users/profiles/9046403.webp)
André van Zyl
- 21
- 4
1
vote
1 answer
match labels with na_tags
The haven package preserves both value labels and tagged NAs when reading Stata/SPSS files. For example, in the GSS's variable for self-employment, the labels suggest there are three different kinds of NA…
![](../../users/profiles/8305581.webp)
lost
- 1,144
- 6
- 13
1
vote
1 answer
Using pull() from dplyr after reading data with haven::read_sas keeps attributes. How to avoid?
I am working with several data sets that originally come as a .sas7bdat file.
Initially, I loaded all files using the sas7bdat package but I am now convinced that the haven package can do a better and quicker job.
However, newly loaded data with…
![](../../users/profiles/6325531.webp)
Frederick
- 654
- 6
- 20
1
vote
1 answer
read_sas: File did not contain the expected number of rows
I am trying to load a .sas7bdat file to R, but get the error
ReadStat: Expected 849278526 rows in file, found 611874762. Failed to parse "filepath": File did not contain the expected number of rows.
What does this error message mean?
My code…
![](../../users/profiles/10888927.webp)
Elke
- 13
- 7
1
vote
0 answers
Error message in read_sas (haven package) using cols_only to read in only subset of columns
I am using the haven packages' read_sas to import a SAS data set. However, I would like to only include a subset of columns. My data set has 613,124 observations and 189 variables. However, I do not seem to be using the "cols_only" argument…
![](../../users/profiles/10601119.webp)
JohnF
- 11
- 2
1
vote
1 answer
Installing RIO Package : shared object ‘haven.so’ not found
I've some problem to install package in R.
I write :
install.packages("rio", dependencies = TRUE)
And it gives the error message:
installing source package ‘rio’ ...
** package ‘rio’ correctement décompressé et sommes MD5 vérifiées
** R
**…
![](../../users/profiles/10433374.webp)
Simon El Puercoespín
- 11
- 2
1
vote
2 answers
extracting Stata labels in R when some variables are missing labels
I'm working with large Stata files with variable names and labels. I need these labels to understand what each variable is.
I have been using
df[] %>% map_chr(~attributes(.)$label)
to extract the variable names and associated labels. Unfortunately…
![](../../users/profiles/5667365.webp)
Calen
- 149
- 2
- 15