r-haven

Hack to to include special characters in file path in haven::read_sav()

白昼怎懂夜的黑 提交于 2020-01-02 01:01:10
问题 There seems to be an issue with the haven (1.1.1) package when including any type of special character in the file path, including just the file name. Assuming this is a real issue I am looking for some kind of neat hack/solution to get around it. An (not ideal) example would be to have R take a copy of the file into a more friendly path and give it a "better" filename and then load with haven. Such as: setwd("c:/temp") fn <- "randóóm.sav" file.copy(paste0("./äglæpath/", fn), fn) file.rename

Dynamically create value labels with haven::labelled, follow-up

落花浮王杯 提交于 2019-12-24 06:08:23
问题 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 export to SPSS. Now, say I have a df value_labels of values and their value labels. I also have a df df_data with variables to which I want allocate value labels. value_labels <- tibble( value = c(seq(1:6), seq(1:3), NA), labels = c(paste0("value", 1:6)

Dynamically create value labels with haven::labelled, follow-up

徘徊边缘 提交于 2019-12-24 06:08:23
问题 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 export to SPSS. Now, say I have a df value_labels of values and their value labels. I also have a df df_data with variables to which I want allocate value labels. value_labels <- tibble( value = c(seq(1:6), seq(1:3), NA), labels = c(paste0("value", 1:6)

Convenient way to access variables label after importing Stata data with haven

情到浓时终转凉″ 提交于 2019-12-03 05:21:55
问题 In R, some packages (e.g. haven ) insert a label attributes to variables (e.g. haven ), which explains the substantive name of the variable. For example, gdppc may have the label GDP per capita . This is extremely useful, especially when importing data from Stata. However, I still struggle to know how to use this in my workflow. How to quickly browse the variable and the variable label? Right now I have to do attributes(df$var) , but this is hardly convenient to get a glimpse (a la names(df)

Convenient way to access variables label after importing Stata data with haven

一个人想着一个人 提交于 2019-12-02 17:44:35
In R, some packages (e.g. haven ) insert a label attributes to variables (e.g. haven ), which explains the substantive name of the variable. For example, gdppc may have the label GDP per capita . This is extremely useful, especially when importing data from Stata. However, I still struggle to know how to use this in my workflow. How to quickly browse the variable and the variable label? Right now I have to do attributes(df$var) , but this is hardly convenient to get a glimpse (a la names(df) ) How to use these labels in plots? Again, I can use attr(df$var, "label") to access the string label.