GithubHelp home page GithubHelp logo

ropensci / essurvey Goto Github PK

View Code? Open in Web Editor NEW
49.0 10.0 9.0 36.32 MB

Download data from the European Social Survey

Home Page: https://docs.ropensci.org/essurvey

License: Other

R 100.00%
ess r rstats r-package

essurvey's Introduction

essurvey

CRAN_Status_Badge R build status Coverage status rOpensci_Badge

Description

The European Social Survey (ESS) is an academically driven cross-national survey that has been conducted across Europe since its establishment in 2001. Every two years, face-to-face interviews are conducted with newly selected, cross-sectional samples. The survey measures the attitudes, beliefs and behavior patterns of diverse populations in more than thirty nations. Taken from the ESS website.

Note: The essurvey package was originally called ess. Since essurvey 1.0.0 all ess_* functions have been deprecated in favor of the import_* and download_* functions. Also, versions less than and including essurvey 1.0.1 returned wrong countries. Please install the latest CRAN/Github version.

The essurvey package is designed to download the ESS data as easily as possible. It has a few helper functions to download rounds (a term synonym to waves to denote the same survey in different time points), rounds for a selected country and to show which rounds/countries are available. Check out the vignette and other documentation in the package’s website for more detailed examples of the essurvey package.

Installation

You can install and load the development version with these commands:

# install.packages("devtools") in case you don't have it
devtools::install_github("ropensci/essurvey")

or the stable version with:

install.packages("essurvey")

Usage

First, you need to register at the ESS website, in case you haven’t. Please visit the register section from the ESS website. If your email is not registered at their website, an error will be raised prompting you to go register.

Set your valid email as en environment variable.

set_email("[email protected]")

To explore which rounds/countries are present in the ESS use the show_*() family of functions.

library(essurvey)
show_countries()
#>  [1] "Albania"            "Austria"            "Belgium"           
#>  [4] "Bulgaria"           "Croatia"            "Cyprus"            
#>  [7] "Czechia"            "Denmark"            "Estonia"           
#> [10] "Finland"            "France"             "Germany"           
#> [13] "Greece"             "Hungary"            "Iceland"           
#> [16] "Ireland"            "Israel"             "Italy"             
#> [19] "Kosovo"             "Latvia"             "Lithuania"         
#> [22] "Luxembourg"         "Montenegro"         "Netherlands"       
#> [25] "Norway"             "Poland"             "Portugal"          
#> [28] "Romania"            "Russian Federation" "Serbia"            
#> [31] "Slovakia"           "Slovenia"           "Spain"             
#> [34] "Sweden"             "Switzerland"        "Turkey"            
#> [37] "Ukraine"            "United Kingdom"

To download the first round to use in R:

one_round <- import_rounds(1)

This will return a data frame containing the first round. Typically, the European Social Survey data files comes with a script that recodes missing values to NA for different programs (Stata, SPSS, SAS).

Use recode_missings to recode all values automatically.

library(tidyverse)

one_round <-
  import_rounds(1) %>%
  recode_missings()

See the package vignette for greater detail or see the help page with ?recode_missings. You can also download several rounds by supplying the number of rounds.

five_rounds <- import_rounds(1:5)

This will download all latest versions of rounds 1 through 5 and return a list of length 5 with each round as a data frame inside the list.

You can check the available rounds with show_rounds() because if you supply a non existent round, the function will return an error.

two_rounds <- import_rounds(c(1, 22))
#> Error in round_url(rounds) : 
#> ESS round 22 is not a available. Check show_rounds() 

Alternatively, you can download all available rounds with import_all_rounds().

You can also download rounds by country:

dk_two <- import_country("Denmark", 1:2)

Use show_countries() to see available countries and show_country_rounds("Denmark") to see available rounds for chosen country. Alternatively, use import_all_cntrounds() to download all available rounds of a country.

You should be be aware that data from the ESS survey should by analyzed by taking into consideration the sampling and weights of the survey. A useful example comes from the work of Anthony Damico and Daniel Oberski here.

Stata, SPSS and SAS users

I’m quite aware that most ESS users don’t know R, that is why the package also allows to download the data in Stata, SPSS or SAS format with just one line of code. Instead of the import_* functions, use the download_* functions.

download_rounds(c(1, 2),
                output_dir = "my/new/directory",
                format = 'spss')

This will save the ESS rounds into separate folders and unzip them in the specified directory (if you want to know your current directory, type getwd()). This works the same way for download_country(). Be aware that if you download the files manually you should read them into R with the haven package for all essurvey related functions to work.


Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

ropensci_footer

essurvey's People

Contributors

briatte avatar cimentadaj avatar jeroen avatar jlopezper avatar sckott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

essurvey's Issues

Add CRAN install to vignette

The vignette has only the development version installation (here). Add the CRAN installation (this way you can also track pkg downloads)

Add show_* fun to see countries that participated in combination of years

Similar to Issue #14, it would also be useful to have a function that the user inputs for example, all rounds, and it returns countries that participated in all rounds. Another example is for the user to input for rounds c(1, 5, 7) and the function returns countries that are present in all three rounds.

How to use weights?

ESS uses three types of weights, for ex. dweight. How to use it with essurvey?

Set output_dir to be saved to working directory

Currently output_dir of any of the ess_* funs is set to NULL to force the user to specify a directory. You could leave it as NULL and internally check whether it's NULL and then save in the working directory by default.

You could also just changed NULL to getwd(). This won't pose a problem to scripts using ess because until now the user HAD to specify output_dir and only_download. The only change now would be that the user is allowed to just specify only_download and output_dir is optional.

Clarify whether show_rounds_country() is an AND or OR logical

The show_rounds_country() function takes a numeric vector of ESS rounds (as integers) and returns participating countries. It's not obvious from the documentation, however, whether the countries that are returned are those that participated in any of those rounds or the set of countries that participated in all of those rounds. Some clarity might be useful or, alternative, two functions (or a new argument to this function) to disambiguate might be appropriate.

Make 'your_email' a global variable

It would be great to do one of the following:

  • Have ESS_EMAIL as an environment variable so it can be set globally and not within each call
  • If not that, then have a function like set_email() that sets a hidden global variable for a given session

New functionality for importing SDDF for round 9

The SDDF for round 9 is integrated with the survey data. Which is great. However, new functionality for importing the SDDF R9 is necessary.

Expected Behavior

SDDF for round 9 can be imported using the import_sddf_country and other relevant function.

Current Behavior

The SDDF for round 9 can be imported using the import_rounds function and extracting the necessary variables.

README file - missing library

Users may be beneficial from the below code to include "library(tidyverse)" to avoid encountering an error "could not find function %>%"

one_round <-
ess_rounds(1, "[email protected]") %>%
recode_missings()

SDDF round 6

Something strange is going on with the SDDF files for the round 6. It was working before but not any more.

For example import_sddf_country(country = "Albania", rounds = 6) returns an error:

> import_sddf_country(country = "Albania", rounds = 6)
Downloading ESS6
  |=====================================================================================| 100%
Error in vapply(dir_download, list.files, pattern = paste0(format_ext,  : 
  values must be length 1,
 but FUN(X[[1]]) result is length 2

However, I do not see anything wrong with the data file as this is working:

> download_sddf_country(country = "Albania", rounds = 6, output_dir = "~/data")
Downloading ESS6
  |=====================================================================================| 100%
All files saved to /home/djhurio/data
> haven::read_stata(file = "~/data/ESS_Albania/ESS6/ESS6_AL_SDDF.dta")
# A tibble: 1,201 x 6
   cntry  idno   psu samppoin stratify     prob
   <chr> <dbl> <dbl>    <dbl> <chr>       <dbl>
 1 AL        1    57       57 6        0.000730
 2 AL        2    80       80 9        0.000418
 3 AL        3   198      198 22       0.000193
 4 AL        4    57       57 6        0.000584
 5 AL        5    72       72 8        0.000427
 6 AL        6   185      185 20       0.0118  
 7 AL        7    49       49 5        0.000445
 8 AL        8    72       72 8        0.000427
 9 AL        9    49       49 5        0.000594
10 AL       10    55       55 6        0.000733
# … with 1,191 more rows

Thanks!

Round 9 data

The first release of the round 9 data is available.

I am getting a warning when importing the round 9 data in Stata format. There is not a warning when importing data in SPSS format.

import_rounds(rounds = 9, format = "stata")

Downloading ESS9
  |=========================================================================| 100%
Warning message:
Round 9  was read with the `foreign` package rather than with  the `haven` package for compatibility reasons.
 Please report any issues at https://github.com/ropensci/essurvey/issues 

Encoding problem with `prtvt` variables

I have an encoding problem with several prtvt variables. For example:

  • prtvtcfi from the round 7;
  • prtvtbis from the round 8.

See the examples.

Here the problem is with party name The Swedish People´s Party (SPP).

> str(dat$prtvtcfi)
Class 'labelled'  atomic [1:75022] NA NA NA NA NA NA NA NA NA NA ...
  ..- attr(*, "label")= chr "Party voted for in last national election, Finland"
  ..- attr(*, "format.stata")= chr "%10.0g"
  ..- attr(*, "labels")= Named num [1:22] 1 2 3 4 5 6 7 8 9 10 ...
  .. ..- attr(*, "names")=Error in strtrim(encodeString(object, quote = "\"", na.encode = FALSE),  : 
  invalid multibyte string at '<b4>s Par<74>y (SPP)"'

Here the problem is with party names from Iceland.

> str(dat$prtvtbis)
Class 'labelled'  atomic [1:75022] NA NA NA NA NA NA NA NA NA NA ...
  ..- attr(*, "label")= chr "Party voted for in last national election, Iceland"
  ..- attr(*, "format.stata")= chr "%12.0g"
  ..- attr(*, "labels")= Named num [1:19] 1 2 3 4 5 6 7 8 9 10 ...
  .. ..- attr(*, "names")=Error in strtrim(encodeString(object, quote = "\"", na.encode = FALSE),  : 
  invalid multibyte string at '<f0>isflo<6b>kinn"'

This is not directly related to your package. I have the same problem if I read ESS data from the STATA data files as well. I do not have this problem if I read ESS data from the SPSS data files.

Delete tempdir() file when only_download = FALSE

When only_download = FALSE, ess_ funs create a tempdir() to store the data. I know that tempdir() is removed when a R session is restarted but make your sure you delete the temporary file with on.exit() because it will leave a cleaner version, especially because downloading all ess files are very heavy.

Make the `country` argument case insensitive

ess_country accepts a country name as a string, taken from show_countries. This is currently case insensitive, but an improvement could be to make it case insensitive avoiding the show_countries step.

Mention survey weights

One of the big questions when using survey data in R is how best to handle weighting. The {survey} package provides very good support for this and most users would need to know (if they don't already) that they need to dump the ESS data into a survey::svydesign() object before doing any analysis. It might be useful to have a second vignette showing how to do this and perform some analyses, or at least mention survey weighting in the README, vignette, and package-level documentation.

Add package-level documentation

Currently, the package does not have a package-level documentation page:

> library("ess")
> ? ess
No documentation foressin specified packages and libraries:
you could try ‘??ess

Having this can be useful for giving new users an obvious landing page.

use git tags and release notes

we're trying to get all ropensci pkgs to use git tags and release notes, as it's common software practice.

In our packaging guide we have some notes on this https://github.com/ropensci/onboarding/blob/master/packaging_guide.md#-news

We'd like each repo to have a git tag associated with each cran release and then the news items for that cran release on the releases tab of your repo. After you do the git tag, you'll then be able to go to Releases tab and edit the release notes for the git tag putting in your news items

thanks!

The access to the ESS data is changing

I am afraid this package will not work from Monday 30 May. This is because of change in ESS data publishing architecture.

European Social Survey (ESS) data and documentation will only be accessible through the new ESS Data Portal from Monday 30 May.
The cumulative data file for all nine rounds, country-specific data, the ESS Cumulative Data Wizard and the Online Analysis Tool (Nesstar) will no longer be available on this date.

Read more at the ESS announcement The way you access our data is changing.

Submit to rOpensci

I just checked out that the package overlaps a lot with the packages from rOpenSci. Check out further requirements to submit the package and if it seems like a good idea, prepare for submission

Distinguish download and import functionality as distinct functions

The ess_rounds() function, and related functions, can both import and simply down a data file. As far as I can tell when importing, the data file is not saved to the local directory. It seems you may want to distinguish these by creating separate download_rounds() and import_rounds() functions since their behavior is quite different - the former is only used for a side effect.

This then has an impact on a feature of ess_rounds() that seems unnecessary for most users: namely, the ability to download different file formats. If the users is only importing into R, it shouldn't matter what file format they download so it might be safe to remove this option entirely from an import_rounds() function.

Add notification of 'ESSR' package on DESCRIPTION

A recent email (here) suggested that this package adds a notification to users that this is not related to the ess r project. The authors of the project suggest adding:

This package ess is named to match the European Social Survey (ESS).
It is unrelated to the Emacs Speaks Statistics (ESS) project, an
emacs-based Integrated Development Environment hosted at
https://ess.r-project.org

in the DESCRIPTION file. Similarly, I've asked them to add the same to their ESSR package.

SDDF pulling error

Expected Behavior

Get SDDF

Current Behavior & Steps to Reproduce

Getting an error when trying to download or get the sddf file
Seems that the host name gets corrupted somehow

library("essurvey")
essurvey::set_email(".@gmail.com")
essurvey::download_sddf_country(country = "Estonia", rounds = 7)
Error in curl::curl_fetch_memory(url, handle = handle) :
Could not resolve host: www.europeansocialsurvey.orghttp

Context

Trying to get an SDDF file for round 7, which doesn't seem to be available on https://www.europeansocialsurvey.org/download.html?file=ESS8SDDFe01_1&y=2014 anymore

Your Environment

devtools::session_info()
─ Session info ────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.1.2 (2021-11-01)
os macOS Big Sur 11.4
system x86_64, darwin17.0
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/Tallinn
date 2022-01-09
rstudio 2021.09.1+372 Ghost Orchid (desktop)
pandoc NA

─ Packages ────────────────────────────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
cachem 1.0.6 2021-08-19 [1] CRAN (R 4.1.0)
callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.0)
cli 3.1.0 2021-10-27 [1] CRAN (R 4.1.0)
colorspace 2.0-2 2021-06-24 [1] CRAN (R 4.1.0)
crayon 1.4.2 2021-10-29 [1] CRAN (R 4.1.0)
curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.0)
desc 1.4.0 2021-09-28 [1] CRAN (R 4.1.0)
devtools 2.4.3 2021-11-30 [1] CRAN (R 4.1.0)
dplyr 1.0.7 2021-06-18 [1] CRAN (R 4.1.0)
ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0)
essurvey * 1.0.7 2021-03-22 [1] CRAN (R 4.1.0)
fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.0)
fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0)
fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.0)
generics 0.1.1 2021-10-25 [1] CRAN (R 4.1.0)
ggplot2 3.3.5 2021-06-25 [1] CRAN (R 4.1.0)
glue 1.6.0 2021-12-17 [1] CRAN (R 4.1.0)
gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.0)
httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.0)
lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.0)
magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0)
memoise 2.0.1 2021-11-26 [1] CRAN (R 4.1.0)
munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.0)
pacman 0.5.1 2019-03-11 [1] CRAN (R 4.1.0)
pillar 1.6.4 2021-10-18 [1] CRAN (R 4.1.0)
pkgbuild 1.3.1 2021-12-20 [1] CRAN (R 4.1.0)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0)
pkgload 1.2.4 2021-11-30 [1] CRAN (R 4.1.0)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0)
processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.0)
ps 1.6.0 2021-02-28 [1] CRAN (R 4.1.0)
purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.0)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0)
remotes 2.4.2 2021-11-30 [1] CRAN (R 4.1.0)
rlang 0.4.12 2021-10-18 [1] CRAN (R 4.1.0)
rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.0)
rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0)
rvest 1.0.2 2021-10-16 [1] CRAN (R 4.1.0)
scales 1.1.1 2020-05-11 [1] CRAN (R 4.1.0)
selectr 0.4-2 2019-11-20 [1] CRAN (R 4.1.0)
sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.0)
stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.0)
stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0)
testthat 3.1.1 2021-12-03 [1] CRAN (R 4.1.0)
tibble 3.1.6 2021-11-07 [1] CRAN (R 4.1.0)
tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0)
usethis 2.1.5 2021-12-09 [1] CRAN (R 4.1.0)
utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0)
vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0)
withr 2.4.3 2021-11-30 [1] CRAN (R 4.1.0)
xml2 1.3.3 2021-11-30 [1] CRAN (R 4.1.0)

[1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library

Stata files need to be pre-processed with their do file before reading

Sent through email by Wiebke Weber.

All ESS Stata files have a corresponding Stata script file (.do files) that recode missing values into similar categories in all questions.

For example, questions with less than 6 categories have missing values coded as 6, 7, 8 and 9 whereas question with more than 6 categories have missing values coded as 66, 77, 88 and 99.

The Stata script automatically recodes all of these to .a, .b, .c and .d, among other pre-processing of the data. It would be nice to pre-process each data file with it's corresponding do file this way so that users don't have to worry about this.

Add a *_themes() to the package

The ESS also allows you to download rounds by themes. It would be a nice addition to include the themes within the ess family of functions. In fact, this should be very straightforward because accessing the provided theme website should be exactly the same way you accessed the country-round website for ess_country() and show_country_rounds().

I think the way to go would be to create a function that summarized this step and the function is implemented in both country and theme websites with arguments for the things that change.

Use match.arg() where appropriate

There are a few places where constructions like the following are used:

# Check if the format is either 'stata', 'spss' or 'sas'.
  if(!format %in% c('stata', 'spss', 'sas')) {
    stop("Format not available. Only 'stata', 'spss', or 'sas'")
  }

This is a great opportunity to use the match.arg() function, which will produce basically the same error message.

import_country and import_all_cntrounds return wrong countries

Luca Salini and Virginia Ros write over email a very serious bug in essurvey. Basically, whenever you specifiy a country to be downloaded, it returns a different country. See reprex below:

library(essurvey)
es <- import_country("Spain", 1:3, you_email_here)
#> Downloading ESS1
#> Downloading ESS2
#> Downloading ESS3

unique(es[[1]]$cntry)
#> [1] "SE"
unique(es[[2]]$cntry)
#> [1] "SE"
unique(es[[3]]$cntry)
#> [1] "SE"

It should return ES for Spain, but rather returns 'SE' for SWEDEN! This has severe consequences as most users of essurvey are downloading countries which are not they ones they are choosing.

Use HTTPS

It looks like the package currently using insecure HTTP calls to authenticate the user, for example:

As well as in several other places. It appears the ESS website supports HTTPS, so it would be good to switch to that if possible. While an email address isn't exactly a super sensitive piece of data, users should be protected to the extent possible. If that's not possible, I would flag it explicitly in the README that this is passing the email address in the open.

ESS round 9 haven vs. foreign

As reported here #44 ESS round 9 data is read with the foreign package due to the fallback option. However as all other rounds imported via import_rounds(set_email = "[email protected]") are read with the haven package, cleaning and merging them into a tidy dataset becomes a chore.

It appears to be esier to go to https://www.europeansocialsurvey.org/download.html?file=ESS9e02&y=2018 and download the SPSS file for round 9 and read it with haven::read_sav("ESS9e02.sav") than to clean all the rounds read with foreign.

Could you please look into, why haven fails with the most recent rounds, when importing via essurvey?

Add message for downloading which country

Currently when downloading the rounds you only get output messages for which round you're downloading, such as

Downloading ESS2
  |=============================================================| 100%
Downloading ESS4
  |=============================================================| 100%
Downloading ESS8
  |=============================================================| 100%

When downloading many datasets from different countries it might be informative to also print the country being downloaded in case the download hangs, and it's easier to debug.

Removed from CRAN?

Package ‘essurvey’ was removed from the CRAN repository.

Formerly available versions can be obtained from the archive.

Archived on 2021-02-27 for policy violation.

Curious to know what policy we violated…

Wrap any GET calls with stop_for_status()

Currently, GET is used to request information from the European Social Survey website without issuing any error of whether the request was successful. It would a good idea to create a function that wraps GET with stop_for_status to convert request errors into R errors so the user can get more informative messages of why the function did not work.

The idea comes from the docs of stop_for_status

using sampling design data files (SDDFs)

@BernStZi, thanks a lot for this explanation! However I do not fully agree with you regarding the design weights. What I have learned and I have always assumed is that designs weights are derived directly from the sampling probabilities. Namely, dweight should be equal to 1 / prob. The name of those weights indicates that those weights are purely derived from the sample design.

I agree that design weights can not be applied in case of non-response. Well, you can, but better results can be gained by applying the so called non-response corrections on weights. This is a usual practice. However, those corrected weights cannot be called design weights, as they are derived taking into account extra information which is more than sampling design is providing.

Originally posted by @djhurio in #9 (comment)

import_country returns error

Hi!

I was just trying to download ESS data using the import_country() function, but found that it returns an error.

I ran:
ess <- import_country(country = "Austria", rounds = 1)

Result: Failed to download, and error message:
Error in curl::curl_fetch_memory(url, handle = handle) : Could not resolve host: www.europeansocialsurvey.orghttp

I get the same error when I try to download data for Norway or Germany, and for round 9 instead of 1, or when I use the example from the help files (Denmark, rounds 1-3).

import_rounds() works as it should, however.

My environment:
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.1.2 (2021-11-01)
os macOS Big Sur 10.16
system x86_64, darwin17.0
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/Oslo
date 2021-12-13

Many thanks in advance!

Remove stringr as dependency

I think I added it at the beginning for no reason but it should be easily removable now since it only uses 1 or 2 functions.

Download data in other formats

The package relies heavily in the haven package for reading Stata files. Given that Stata version change quite often it could be the case that a ESS data is updated to a Stata format not yet supported by haven.

A more robust solution would be having the option to also downloading the files as SPSS or SAS formats, two formats which don't change that often.

Unexpected behavior about missing values

  • I would expect that the following lines do not recode missingness due to, for instance, 'Refusal." Instead, I see NA for 'Refusal.'
library(essurvey)
Round8 <- import_rounds(8)
data.frame(tail(attr(Round8$edulvlb, "labels"), 5))

tail.attr.Round8.edulvlb...labels....5.

ISCED 6, doctoral degree 800
Other 5555
Refusal NA
Don't know NA
No answer NA

  • The following code behaves as expected:
Round8 <- import_rounds(8)
recode_missings(Round8)
data.frame(tail(attr(Round8$edulvlb, "labels"), 5))

tail.attr.Round8.edulvlb...labels....5.

ISCED 6, doctoral degree 800
Other 5555
Refusal NA
Don't know NA
No answer NA

  • The following unexpectedly loses the missingness categories "Refusal", "Don't know", and "No answer" altogether. I would expect the output to be the same as above.
Round8 <- import_rounds(8)
Round8 <- recode_missings(Round8)
data.frame(tail(attr(Round8$edulvlb, "labels"), 2))

ISCED 6, doctoral degree 800
Other 5555

devtools::session_info()

  • Session info -------------------------------------
    setting value
    version R version 3.5.2 (2018-12-20)
    os Windows >= 8 x64
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate English_United States.1252
    ctype English_United States.1252
    tz America/Denver
    date 2019-04-27

  • Packages ----------------------------------------------------
    package * version date lib source

essurvey * 1.0.2 2018-08-23 [1] CRAN (R 3.5.2)

Add tests for validity of arguments

These scenarios should check the arguments first and give out informative errors:

library(essurvey)

import_country(character(), numeric())
#> Error in module_list[[module]]: attempt to select less than one element in get1index

import_country("Spain", numeric())
#> Downloading NA
#> 
Downloading: 5.6 kB     
Downloading: 5.6 kB     
Downloading: 5.6 kB     
Downloading: 5.6 kB
#> Warning in utils::unzip(temp_download, exdir = which_folder): error 1 in
#> extracting from zip file
#> list()

import_country(character(), 1)
#> Error in module_list[[module]]: attempt to select less than one element in get1index

Import SDDF for France rounds 1:3

Expected Behavior

SDDF data for France rounds 1:3 should be imported with haven.

Current Behavior

I am receiving a warning that fallback to foreign has happened.

Steps to Reproduce (for bugs)

Input:

import_sddf_country(country = "France", rounds = 1:3)

Output:

Warning messages:
1: Round 1 for France was read with the `foreign` package rather than with  the `haven` package for compatibility reasons.
 Please report any issues at https://github.com/ropensci/essurvey/issues

Your Environment

─ Session info ───────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.1 (2020-06-06)
 os       Linux Mint 19.3             
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  lv_LV.UTF-8                 
 ctype    lv_LV.UTF-8                 
 tz       Europe/Riga                 
 date     2020-06-17     

Exclude countries with no rounds from show_countries

show_countries show countries such as Serbia and Montenegro which are to appear in ESS9 as their first round. show_country_rounds knows how to exclude rounds which are still not available (ESS9) but show_countries includes them. See the table here.

# Serbia is here
show_countries()

#>  [1] "Albania"            "Austria"            "Belgium"           
#>  [4] "Bulgaria"           "Croatia"            "Cyprus"            
#>  [7] "Czechia"            "Denmark"            "Estonia"           
#> [10] "Finland"            "France"             "Germany"           
#> [13] "Greece"             "Hungary"            "Iceland"           
#> [16] "Ireland"            "Israel"             "Italy"             
#> [19] "Kosovo"             "Latvia"             "Lithuania"         
#> [22] "Luxembourg"         "Montenegro"         "Netherlands"       
#> [25] "Norway"             "Poland"             "Portugal"          
#> [28] "Romania"            "Russian Federation" "Serbia"            
#> [31] "Slovakia"           "Slovenia"           "Spain"             
#> [34] "Sweden"             "Switzerland"        "Turkey"            
#> [37] "Ukraine"            "United Kingdom"
    
# But there no rounds. This makes sense once you look at the link from above.
show_country_rounds('Serbia')

#> numeric(0)

Add show_regions()

Similar to every show_ functions, a handy feature would be to also know the NUTS1, NUTS2 and other regional disaggregates for every country and wave. The problem is that the NUTS tables are interactive rather than static html tables I believe.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.