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
2
votes
0 answers
total() in tab_cols only sum up to one, any suggestion?
Suppose I have dataframe 'y'
WR<-c("S",'J',"T")
B<-c("b1","b2","b3")
wgt<-c(0.3,2,3)
y<-data.frame(WR,B,wgt)
I want to make column percentage crosstab with B as row, WR, and total of WR as columns using expss function
library(expss)
y %>%…

Szicocs
- 21
- 2
2
votes
1 answer
R haven package call generating: ***Recursive gc invocation
Anyone run into the R haven package call generating: ***Recursive gc invocation error in a shared environment?
Here is what I am running.
RStudio Ver. 2021.09.2 Build 382
R Ver. 4.1.2
Rtools Vers 4.0
Haven package release 2.4.3
The code works on my…

Rocknotes
- 21
- 1
- 3
2
votes
2 answers
How to reference variable label in graph in R?
Hi I am using labelled data in R with the haven and sjlabelled packages. I want to reference the variable's label when I graph it. It works if I directly reference the dataframe and the label (see get_label function in the graph's…

Kate Ham
- 143
- 6
2
votes
1 answer
Unable to read SAS Transport File in R using Haven
I'm trying to view a SAS Transport File provided by CMS HCC risk adjustment model software files (2020 Model Software (zip)).
I already tried to open with SAS Universal Viewer to no luck.
Also tried reading in the file using library(haven) by doing…

Jebediah15
- 754
- 3
- 18
- 39
2
votes
2 answers
How to create a ggplot when the answers are FALSE or TRUE?
How can I create a plot with ggplot when my answers are TRUE or FALSE?
This is my code:
t.obese<-master1%>%
filter(Income>0,obese==TRUE)%>%
select(Income,obese)
> head(t.obese)
Income obese
1 21600 TRUE
2 4000 TRUE
3 12720 TRUE
4…

Lin
- 73
- 1
- 7
2
votes
1 answer
Recoding one hevan_labelled variable
I tried to recode one variable of a dataset of a complex survey.
I have tried dplyr::recode function.
occup<-recode(sv$v717, c(0 )='0'; c(1, 2, 3 )='1'; c(4 )='2'; c(8, 9 )='3'; c(96, 98)='98'")
Earlier I did same way successfully.
However, this…

Md Shariful Islam
- 71
- 8
2
votes
2 answers
Writing failure: A provided name contains an illegal character. Error while saving R data into Stata format
I am using haven package to write the R dataset into Stata format.
This is the error I am getting.
write_dta(road_panel, "road_panel.dta", version = 14, label = attr(data,"label"))
Error in write_dta_(data, normalizePath(path, mustWork = FALSE),…

Fuser
- 47
- 1
- 9
2
votes
0 answers
How can I change haven_labelled variables to factor and numeric variables that can be adequate for R?
I am using Demographic and Health Survey data and want to convert the data from wide to long.
However, I got an error when I used tidyr::pivot_longer.
I imported the data from PSPP (.sav) using read_sav from the haven package. The resulting…

Mariela Contreras
- 31
- 5
2
votes
1 answer
r - read zip file from s3 using r
Is it possible to read a zipped sas file (or any kind or file) from s3 using r?
Here is what I'm trying:
library(aws.s3)
library(haven)
s3read_using(FUN = read_sas(unzip(.)),
bucket = "s3://bucket/",
object =…

alexb523
- 718
- 2
- 9
- 26
2
votes
1 answer
Extract haven_labelled vector's label as a vector of strings
I've got a haven_labelled vector, from which I want to extract its labels as a vector of strings:
library(haven)
vec <- structure(c(1, 2, 3, 1, 2, 3), label = "Región", labels = c(`one` = 1, `two` = 2, `three` = 3),
class =…

David Jorquera
- 2,046
- 12
- 35
2
votes
1 answer
Dynamically create value labels with haven::labelled, follow-up
Follow-up question to Dynamically create value labels with haven::labelled, where akrun provided a good answer using deframe.
I am using haven::labelled to set value labels of a variable. The goal is to create a fully documented dataset I can…

oskjerv
- 198
- 7
2
votes
1 answer
read_sas cols_only supress error Evaluation error: Column 2 must be named
I have a long list of very large SAS files. I want to import them using read_sas. To increase speed and reduce memory usage I want to only import the columns I am interested in using cols_only.
The trouble is, I have a long list of possible column…

Jonathan Nolan
- 135
- 9
2
votes
1 answer
How to load .dta (preserving labels) most comfortable in R?
I work with .dta files and try to make loading data as comfortable as possible. In my view, I need a combination of haven and readstata13.
haven looks perfect. It provides best "sub-labels". But it does not provide a column-selector-function. I…

Marco
- 2,368
- 6
- 22
- 48
2
votes
1 answer
How can I check the type of a column if it is an unusual type?
I have some SPSS data from a .sav file and am trying to work with it in R. Many of the variables are of type haven_labelled. I'd like to convert them to double using mutate_if(). How can I create a predicate for mutate_if() that will catch all the…

JohnDoeVsJoeSchmoe
- 671
- 2
- 8
- 25
2
votes
0 answers
R: How to read in a SAS dataset with all columns as character
I'm using R to tidy data supplied to me (in a SAS file) so that I can bulk insert it into a SQLserver database. The problem that I'm having is that sometimes numeric fields get transformed by R after I read them in eg.(the leading 0 gets dropped,…

Maharero
- 238
- 1
- 10