├── .Rbuildignore ├── .Rprofile ├── .github ├── .gitignore ├── CONTRIBUTING.md ├── issue_template.md ├── pull_request_template.md └── workflows │ ├── R-CMD-check.yaml │ ├── pkgdown.yaml │ └── test-coverage.yaml ├── .gitignore ├── .travis.yml ├── CONDUCT.md ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── check_args.R ├── download_format.R ├── essurvey-package.R ├── import_countries.R ├── import_rounds.R ├── import_sddf_country.R ├── read_format_data.R ├── recode_missings.R ├── set_email.R ├── show_any_rounds.R ├── show_funs.R ├── show_sddf_cntrounds.R └── url_funs.R ├── README.Rmd ├── README.md ├── appveyor.yml ├── codecov.yml ├── codemeta.json ├── cran-comments.md ├── docs ├── 404.html ├── CONDUCT.html ├── CONTRIBUTING.html ├── LICENSE-text.html ├── LICENSE.html ├── NEWS.html ├── articles │ ├── index.html │ └── intro_ess.html ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── cran-comments.html ├── docsearch.css ├── docsearch.js ├── index.html ├── issue_template.html ├── jquery.sticky-kit.min.js ├── link.svg ├── man │ └── figures │ │ └── ess_logo.png ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── pull_request_template.html ├── reference │ ├── Rplot001.png │ ├── ess-package.html │ ├── ess_all_cntrounds.html │ ├── ess_all_rounds.html │ ├── ess_country.html │ ├── ess_rounds.html │ ├── essurvey-package.html │ ├── figures │ │ └── ess_logo.png │ ├── import_country.html │ ├── import_rounds.html │ ├── import_sddf_country.html │ ├── index.html │ ├── recode_missings.html │ ├── set_email.html │ ├── show_countries.html │ ├── show_country_rounds.html │ ├── show_rounds.html │ ├── show_rounds_country.html │ ├── show_sddf_cntrounds.html │ ├── show_theme_rounds.html │ └── show_themes.html └── sitemap.xml ├── essurvey.Rproj ├── inst └── CITATION ├── man ├── essurvey-package.Rd ├── figures │ └── ess_logo.png ├── import_country.Rd ├── import_rounds.Rd ├── import_sddf_country.Rd ├── recode_missings.Rd ├── set_email.Rd ├── show_countries.Rd ├── show_country_rounds.Rd ├── show_rounds.Rd ├── show_rounds_country.Rd ├── show_sddf_cntrounds.Rd ├── show_theme_rounds.Rd └── show_themes.Rd ├── revdep ├── check.R └── checks.rds ├── tests ├── testthat.R └── testthat │ ├── test-1-show_.R │ ├── test-2-country.R │ ├── test-3-rounds.R │ ├── test-4-recode_missings.R │ ├── test-6-country_lookup.R │ └── test-7-set_email.R └── vignettes ├── intro_ess.Rmd ├── intro_ess.Rmd.orig └── precompile.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^appveyor\.yml$ 2 | ^.*\.Rproj$ 3 | ^\.Rproj\.user$ 4 | ^packrat/ 5 | ^\.Rprofile$ 6 | ^README.Rmd 7 | ^\.travis\.yml$ 8 | ^cran-comments\.md$ 9 | ^CONDUCT\.md$ 10 | ^revdep$ 11 | ^codecov\.yml$ 12 | ^LICENSE\.md$ 13 | ^docs$ 14 | ^\.github$ 15 | ^codemeta\.json$ 16 | ^intro_ropensci\.*$ 17 | ^intro_ropensci.Rmd$ 18 | ^CRAN-RELEASE$ 19 | ^vignettes/precompile.R$ 20 | -------------------------------------------------------------------------------- /.Rprofile: -------------------------------------------------------------------------------- 1 | if (interactive()) { 2 | cat("One important thing:\n 3 | * If you've just cloned the repository, remember to create a new .Renviron files which has\nthese two variables set (filling out your email):\n 4 | ESS_EMAIL = '' 5 | NOT_CRAN = 'true'\n\n") 6 | } 7 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # CONTRIBUTING # 2 | 3 | ### Bugs? 4 | 5 | * Submit an issue on the [Issues page](https://github.com/ropensci/essurvey/issues) 6 | 7 | ### Issues and Pull Requests 8 | 9 | If you are considering a pull request, you may want to open an issue first to discuss with the maintainer(s). 10 | 11 | ### Code contributions 12 | 13 | * Fork this repo to your GitHub account 14 | * Clone your version on your account down to your machine from your account, e.g,. `git clone https://github.com/ropensci/essurvey.git` 15 | * Make sure to track progress upstream (i.e., on our version of `essurvey` at `ropensci/essurvey`) by doing `git remote add upstream https://github.com/ropensci/essurvey.git`. Before making changes make sure to pull changes in from upstream by doing either `git fetch upstream` then merge later or `git pull upstream` to fetch and merge in one step 16 | * Make your changes (bonus points for making changes on a new feature branch - see for how to contribute by branching, making changes, then submitting a pull request) 17 | * Push up to your account 18 | * Submit a pull request to home base (likely master branch, but check to make sure) at `ropensci/essurvey` 19 | 20 | ### Discussion forum 21 | 22 | Check out our [discussion forum](https://discuss.ropensci.org) if you think your issue requires a longer form discussion. 23 | 24 | ### Prefer to Email? 25 | 26 | Email the person listed as maintainer in the `DESCRIPTION` file of this repo. 27 | 28 | Though note that private discussions over email don't help others - of course email is totally warranted if it's a sensitive problem of any kind. 29 | 30 | ### Thanks for contributing! -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | ## Expected Behavior 2 | 3 | 4 | 5 | ## Current Behavior 6 | 7 | 8 | 9 | ## Steps to Reproduce (for bugs) 10 | 11 | 12 | 1. 13 | 2. 14 | 3. 15 | 4. 16 | 17 | ## Possible Solution 18 | 19 | 20 | 21 | ## Context 22 | 23 | 24 | 25 | ## Your Environment 26 | 27 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ## Description 6 | 7 | 8 | ## Related Issue 9 | 12 | 13 | ## Example 14 | 16 | 17 | ## Best Practices 18 | 20 | The following have been updated or added as needed: 21 | [ ] Documentation 22 | [ ] Examples in documentation 23 | [ ] Vignettes 24 | [ ] `testthat` Tests 25 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. 2 | # https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | pull_request: 9 | branches: 10 | - main 11 | - master 12 | 13 | name: R-CMD-check 14 | 15 | jobs: 16 | R-CMD-check: 17 | runs-on: ${{ matrix.config.os }} 18 | 19 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 20 | 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | config: 25 | - {os: windows-latest, r: 'release'} 26 | - {os: macOS-latest, r: 'release'} 27 | - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} 28 | - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} 29 | 30 | env: 31 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 32 | RSPM: ${{ matrix.config.rspm }} 33 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 34 | ESS_EMAIL: ${{ secrets.ESS_EMAIL }} 35 | 36 | steps: 37 | - uses: actions/checkout@v2 38 | 39 | - uses: r-lib/actions/setup-r@v1 40 | with: 41 | r-version: ${{ matrix.config.r }} 42 | 43 | - uses: r-lib/actions/setup-pandoc@v1 44 | 45 | 46 | - name: Query dependencies 47 | run: | 48 | options(repos = c(CRAN = "https://cran.rstudio.com")) 49 | install.packages('remotes') 50 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 51 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") 52 | shell: Rscript {0} 53 | 54 | - name: Restore R package cache 55 | if: runner.os != 'Windows' 56 | uses: actions/cache@v2 57 | with: 58 | path: ${{ env.R_LIBS_USER }} 59 | key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} 60 | restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- 61 | 62 | - name: Install system dependencies 63 | if: runner.os == 'Linux' 64 | run: | 65 | while read -r cmd 66 | do 67 | eval sudo $cmd 68 | done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') 69 | 70 | - name: Install dependencies 71 | run: | 72 | options(repos = c(CRAN = "https://cran.rstudio.com")) 73 | remotes::install_deps(dependencies = TRUE) 74 | remotes::install_cran("rcmdcheck") 75 | shell: Rscript {0} 76 | 77 | - name: Check 78 | env: 79 | _R_CHECK_CRAN_INCOMING_REMOTE_: false 80 | run: | 81 | options(crayon.enabled = TRUE) 82 | rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") 83 | shell: Rscript {0} 84 | 85 | - name: Upload check results 86 | if: failure() 87 | uses: actions/upload-artifact@main 88 | with: 89 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results 90 | path: check 91 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | - master 6 | 7 | name: pkgdown 8 | 9 | jobs: 10 | pkgdown: 11 | runs-on: macOS-latest 12 | env: 13 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - uses: r-lib/actions/setup-r@v1 18 | 19 | - uses: r-lib/actions/setup-pandoc@v1 20 | 21 | - name: Query dependencies 22 | run: | 23 | options(repos = c(CRAN = "https://cran.rstudio.com")) 24 | install.packages('remotes') 25 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 26 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") 27 | shell: Rscript {0} 28 | 29 | - name: Restore R package cache 30 | uses: actions/cache@v2 31 | with: 32 | path: ${{ env.R_LIBS_USER }} 33 | key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} 34 | restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- 35 | 36 | - name: Install dependencies 37 | run: | 38 | options(repos = c(CRAN = "https://cran.rstudio.com")) 39 | remotes::install_deps(dependencies = TRUE) 40 | install.packages("pkgdown", type = "binary") 41 | shell: Rscript {0} 42 | 43 | - name: Install package 44 | run: R CMD INSTALL . 45 | 46 | - name: Deploy package 47 | run: | 48 | git config --local user.email "actions@github.com" 49 | git config --local user.name "GitHub Actions" 50 | Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' 51 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | - master 6 | pull_request: 7 | branches: 8 | - main 9 | - master 10 | 11 | name: test-coverage 12 | 13 | 14 | jobs: 15 | test-coverage: 16 | runs-on: macOS-latest 17 | env: 18 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 19 | ESS_EMAIL: ${{ secrets.ESS_EMAIL }} 20 | steps: 21 | - uses: actions/checkout@v2 22 | 23 | - uses: r-lib/actions/setup-r@v1 24 | 25 | - uses: r-lib/actions/setup-pandoc@v1 26 | 27 | - name: Query dependencies 28 | run: | 29 | options(repos = c(CRAN = "https://cran.rstudio.com")) 30 | install.packages('remotes') 31 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 32 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") 33 | shell: Rscript {0} 34 | 35 | - name: Restore R package cache 36 | uses: actions/cache@v2 37 | with: 38 | path: ${{ env.R_LIBS_USER }} 39 | key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} 40 | restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- 41 | 42 | - name: Install dependencies 43 | run: | 44 | options(repos = c(CRAN = "https://cran.rstudio.com")) 45 | install.packages(c("remotes")) 46 | remotes::install_deps(dependencies = TRUE) 47 | remotes::install_cran("covr") 48 | shell: Rscript {0} 49 | 50 | - name: Test coverage 51 | run: covr::codecov() 52 | shell: Rscript {0} 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Renviron 5 | inst/doc 6 | /revdep/.cache.rds 7 | intro_ropensci.* 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | sudo: false 5 | cache: packages 6 | 7 | env: 8 | - NOT_CRAN=true 9 | 10 | r_github_packages: 11 | - r-lib/covr 12 | after_success: 13 | - Rscript -e 'covr::codecov()' 14 | notifications: 15 | slack: 16 | secure: IwEjNKm8jXWYMRcXlY9OtMphJs/PWqs1mE2SKLUzYRbo8dYnJ6LqqHVua+7nh/xZYu4hrq6NYDFg5vfDTAfIkvd66dP8UyerfSb9jCw+RkUzBKH6YTtlrmQdgbORvSsHY70G752cOGXkza8MWC7XJT0W7DFz1pg2gBsQHdsQ7cR3CdldxNjyaDM24HHAGKVsLVvBMUGb6Dmzvl4fXWk06MeU36+75NneBp8bMJg+dxZlyzilGPszTMitiEe3l1oKLWkOkvOgDuYpECWIYH6cw1tb4jrffR4DITzCMqaYEGXCZdGTFmd7xyNYcXX8fV3gYKukuvvkDgVOXP7TCchieigKkADfsJ05wnYWpppFP196iak0qtUmvZw63zz9GyfkNMQAmVOUt8GMwpowHUlu8q+aFAhZhUNBtY4MvWcnE3E9ltzUGxxCe/1eBstKUSudtnWEEGTQMSnp1nT7bdvZAUtRAYy2PmjIpZpMH+gChpnRcTcDZup7LHQ9wXke3i+JKkPnASrfQd+v+ugnBHqBJ6Oxzj1iFI3g2Ob7jXNPgeXLWDf0M65/BCjhE/3UFoOXN3h7WkTM2JMcmVw7uSVjdkhFdRUxhiCZrs/5GekEapWlFUcO284XUF5TXbx02PhswIZx9OO2hq1BvGjPGY9QC54U2BahDciMKbmn+AQ2Bvg= 17 | -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http:contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/ 26 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: essurvey 2 | Title: Download Data from the European Social Survey on the Fly 3 | Version: 1.0.8 4 | Date: 2022-01-09 5 | Authors@R: c( 6 | person("Jorge", "Cimentada", email = "cimentadaj@gmail.com", role = c("aut", "cre")), 7 | person("Thomas", "Leeper", role = "rev", comment = "Thomas reviewed the package for rOpensci,see https://github.com/ropensci/software-review/issues/201"), 8 | person("Nujcharee", "Haswell", role = "rev", comment = "Nujcharee reviewed the package for rOpensci, see https://github.com/ropensci/software-review/issues/201"), 9 | person("Jorge", "Lopez", email = "jorge@loperez.com", role = c("ctb")), 10 | person("François", "Briatte", email = "f.briatte@gmail.com", role = c("ctb")) 11 | ) 12 | BugReports: https://github.com/ropensci/essurvey/issues 13 | Description: Download data from the European Social Survey directly from their website . There are two families of functions that allow you to download and interactively check all countries and rounds available. 14 | Depends: R (>= 3.4.0) 15 | License: MIT + file LICENSE 16 | URL: https://docs.ropensci.org/essurvey/, https://github.com/ropensci/essurvey 17 | Encoding: UTF-8 18 | RoxygenNote: 7.1.1 19 | Imports: 20 | xml2, 21 | httr, 22 | haven (>= 2.1.0), 23 | rvest, 24 | tibble, 25 | utils 26 | Suggests: 27 | foreign, 28 | testthat (>= 2.1.0), 29 | knitr, 30 | rmarkdown, 31 | covr 32 | VignetteBuilder: knitr 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2018 2 | COPYRIGHT HOLDER: Jorge Cimentada 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2018 Jorge Cimentada 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(download_country) 4 | export(download_rounds) 5 | export(download_sddf_country) 6 | export(import_all_cntrounds) 7 | export(import_all_rounds) 8 | export(import_all_sddf_cntrounds) 9 | export(import_country) 10 | export(import_rounds) 11 | export(import_sddf_country) 12 | export(recode_missings) 13 | export(recode_numeric_missing) 14 | export(recode_strings_missing) 15 | export(set_email) 16 | export(show_countries) 17 | export(show_country_rounds) 18 | export(show_rounds) 19 | export(show_rounds_country) 20 | export(show_sddf_cntrounds) 21 | export(show_theme_rounds) 22 | export(show_themes) 23 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # essurvey 1.0.8.9999 2 | 3 | # essurvey 1.0.8 4 | 5 | - Fixes URL creation bug (#53) 6 | 7 | # essurvey 1.0.7 8 | 9 | - CRAN maintenance release. All vignettes are now precompiled to avoid errors when the ESS website breaks for some reason. 10 | - `ess_email` environmental variable has been renamed to `ESS_EMAIL` to comply with Github Actions standards 11 | 12 | # essurvey 1.0.6 13 | 14 | - CRAN maintenance release to fix Solaris warnings `Warning in engine$weave(file, quiet = quiet, encoding = enc) : Pandoc (>= 1.12.3) and/or pandoc-citeproc not available. Falling back to R Markdown v1` on CRAN. Tested on Rhub and all passes OK, notifying CRAN. 15 | 16 | - Removes automatic citation message when loading package. It's actually annoying. 17 | 18 | # essurvey 1.0.5 19 | 20 | CRAN maintenance release to add more informative message when the status code of the HTTP request of 'www.europeansocialsurvey.org' is more than 300. 21 | 22 | ## Minor changes 23 | 24 | All tests/examples are now excluded from running on CRAN based on the warning from Brian Ripley: 25 | 26 | 'Packages which use Internet resources should fail gracefully with an 27 | informative message if the resource is not available (and not give a check 28 | warning nor error).' 29 | 30 | They are all forced to run on Travis and Appveyor and this is made clear on the `cran-comments.md` 31 | 32 | # essurvey 1.0.4 33 | 34 | CRAN maintenance check after release of ESS round 9. 35 | 36 | # essurvey 1.0.3 37 | 38 | ## Breaking changes 39 | 40 | * If you don't know which format is available for a round/country, `import_*` and `download_*` functions now accept a NULL argument which runs through `'stata'`, `'spss'` and `'sas'` formats automatically. By default, `import_*` functions have now format set to `NULL` to automatically try the three different formats. This breaks backward dependency but only slightly where it had 'stata' set as default. 41 | 42 | ## New features 43 | 44 | * Users can now download SDDF (weight data) for each country/round combination of files. Functions `show_sddf_cntrounds`, `import_sddf_country` and `download_sddf_country` are now introduced. For technical purposes, `show_sddf_cntrounds` needs for the user to have set their registered ESS email with `set_email`. [#9] 45 | 46 | ## Minor changes 47 | 48 | * Bumps `haven` to minimum package version 2.1.1 49 | * New package website at https://docs.ropensci.org/essurvey 50 | 51 | ## Internal 52 | 53 | * `read_format_data` now tries to read data using `haven` but falls backs to `foreign` in case there's an error. This should only work for SDDF data [#38]. 54 | * `read_format_data` and `read_sddf_data` now always return a list. Checking the length of data to return a data frame now happens within each `import_*` function. 55 | 56 | ## Bug fixes 57 | 58 | * Removes an unnecessary if statement in `set_email` that didn't allow to overwrite the email once set. 59 | 60 | # essurvey 1.0.2 61 | 62 | ## Minor changes 63 | 64 | * `show_country_rounds` checks if there are missing values and excludes them. 65 | 66 | ## Breaking changes 67 | 68 | `import_all_cntrounds` and `import_country` returned incorrect countries [#31] 69 | 70 | # essurvey 1.0.1 71 | 72 | ## Minor changes 73 | 74 | * `ess_email` is now checked that it is not `""` because it wasn't raising an error before. 75 | 76 | * Removes the `round` argument from `import_all_cntrounds` because it was a mistake. It already grabs the rounds internally. 77 | 78 | # essurvey 1.0.1 79 | 80 | Minor release 81 | 82 | * Fixes test that checks the number of rounds that each country has. This test was a mistake 83 | because the rounds will change as time passes by and precise country rounds shouldn't be 84 | tested. 85 | 86 | # essurvey 1.0.0 87 | 88 | The `ess` package has been renamed to `essurvey` for a name conflict with Emacs Speaks Statistics (ESS). See R-pkg mailing list, the post related to the release of ess-0-0-1. 89 | 90 | ## Breaking changes 91 | 92 | * `ess_rounds` and `ess_all_rounds` are deprecated and will be removed in the next release. Use `import_rounds` instead [#22] 93 | 94 | * `ess_country` and `ess_all_cntrounds` are deprecated and will be removed in the next release. Use `import_countries` instead [#22] 95 | 96 | * The `your_email` argument name of `ess_*` functions has be changed to `ess_email` [#23] 97 | 98 | ## New features 99 | 100 | * `import_rounds`, `import_all_rounds` and `download_rounds` have been introduced as 101 | replacements of `ess_rounds` and `ess_all_rounds`. Same changes were repeated for 102 | `ess_country` and `ess_all_cntrounds` [#22] 103 | 104 | * `set_email` to set your email as environmental variable rather than write it in each call [#23] 105 | 106 | * All requests to the ESS website are now done through HTTPS rather than HTTP [#24] 107 | 108 | * Add package level documentation [#20] 109 | 110 | ## Minor changes 111 | 112 | * `ess_email` had no default value but now has `NULL` as default [#23] 113 | 114 | * The `format` argument is now checked through `match.arg` rather than manual check [#25] 115 | 116 | # ess 0.1.1 (2018-03-05) 117 | 118 | ## Breaking changes 119 | 120 | * Downloading 1 round both for countries or single rounds now returns a data frame rather than a list. If download is more than two rounds it returns a list. [#8] 121 | 122 | ## New features 123 | 124 | * remove_missings() together with remove_numeric_missings() and remove_character_missings() now allow you to recode the typical categories 'Not applicable', 'Don't know', etc.. into NA's. See the vignette example for more details. [#1] 125 | 126 | * Can download files in 'stata', 'spss' and 'sas' formats for all functions (both for downloading to user's directory and for reading data). [#11] 127 | 128 | * show_themes() and show_theme_rounds() now available to see which themes have been included in which rounds. [#7] 129 | 130 | * show_rounds_country() is now available to see which countries participated in which rounds [#14] 131 | 132 | ## Bug fixes 133 | 134 | * The `ouput_dir` argument is now set to `getwd()` rather than `NULL` as default. [#16] 135 | 136 | * When parsing country rounds from the ESS table from the website, shaded dots were being interpreted as valid rounds when in fact they're not. show_* funs new exclude shaded dots until they've been added as valid rounds 137 | 138 | * If any `ess_*` function can not connect to the ESS website they will return an explicit R error. [#12] 139 | 140 | * `ess_all_cntrounds` and `ess_all_rounds` were returning the directory of each of the files. Now they only return the single directory where the files where saved as a message 141 | 142 | # ess 0.0.1 (2017-11-07) 143 | 144 | First release 145 | -------------------------------------------------------------------------------- /R/check_args.R: -------------------------------------------------------------------------------- 1 | ## TODO 2 | ## Properly document these functions if you want to export them. 3 | ## Think about it or ask in the issues? 4 | check_rounds <- function(rounds) { # nocov start 5 | all_rounds_present <- rounds %in% show_rounds() 6 | 7 | if (!all(all_rounds_present)) { 8 | 9 | failed_rounds <- paste0(rounds[!all_rounds_present], collapse = ", ") 10 | 11 | stop( 12 | paste("ESS round", failed_rounds, 13 | "is not available. Check show_rounds()") 14 | ) 15 | } 16 | 17 | TRUE 18 | } # nocov end 19 | 20 | check_country <- function(country) { # nocov start 21 | 22 | if (length(country) > 1) stop("Argument `country` should only contain one country") 23 | 24 | all_countries_present <- country %in% show_countries() 25 | 26 | 27 | if (!all(all_countries_present)) { 28 | 29 | failed_countries <- paste0(country[!all_countries_present], collapse = ", ") 30 | 31 | stop( 32 | paste("Country", failed_countries, 33 | "not available in ESS. Check show_countries()", 34 | collapse = "\n") 35 | ) 36 | } 37 | 38 | TRUE 39 | } # nocov end 40 | 41 | 42 | check_country_rounds <- function(country, rounds) { # nocov start 43 | 44 | check_country(country) 45 | 46 | all_rounds_present <- rounds %in% show_country_rounds(country) 47 | 48 | if (!all(all_rounds_present)) { 49 | 50 | failed_rounds <- paste0(rounds[!all_rounds_present], collapse = ", ") 51 | 52 | stop( 53 | paste0("ESS round ", failed_rounds, 54 | " not available for ", country, 55 | ". Check show_country_rounds('", country, "')") 56 | ) 57 | } 58 | 59 | TRUE 60 | } # nocov end 61 | 62 | check_country_sddf_rounds <- function(country, rounds) { # nocov start 63 | 64 | check_country(country) 65 | 66 | all_rounds_present <- rounds %in% show_sddf_cntrounds(country) 67 | 68 | if (!all(all_rounds_present)) { 69 | 70 | failed_rounds <- paste0(rounds[!all_rounds_present], collapse = ", ") 71 | 72 | stop( 73 | paste0("ESS round ", failed_rounds, 74 | ifelse(length(all_rounds_present) > 1, " don't", " doesn't"), 75 | " have SDDF data available for ", country, 76 | ". Check show_sddf_cntrounds('", country, "')") 77 | ) 78 | } 79 | 80 | TRUE 81 | } # nocov end 82 | 83 | check_theme <- function(theme) { # nocov start 84 | 85 | if (length(theme) > 1) stop("Argument `theme` should only contain one theme") 86 | 87 | all_theme_present <- theme %in% show_themes() 88 | 89 | if (!all(all_theme_present)) { 90 | 91 | stop( 92 | paste0("ESS theme ", theme, " not available. Check show_themes()") 93 | ) 94 | } 95 | 96 | TRUE 97 | } # nocov end 98 | 99 | validate_arguments <- function(country, round) { 100 | stopifnot(is.character(country), length(country) > 0) 101 | stopifnot(is.character(round), length(round) > 0) 102 | } 103 | -------------------------------------------------------------------------------- /R/download_format.R: -------------------------------------------------------------------------------- 1 | # Function downloads the rounds or country rounds specified with ess_email and saves 2 | # in output_dir unzipped as the format specified in format (only supports sas, spss and stata). 3 | # If only_download, function will print a out a message where it saved everything. 4 | # the specifi ess_* functions takes care of deleting the folders in only_downloader was FALSE. 5 | 6 | # If only wants to download rounds, then name every argument after rounds. 7 | # If rounds and country are specified, country rounds will be downloaded. 8 | download_format <- function(country, 9 | urls, 10 | ess_email = NULL, 11 | only_download = FALSE, 12 | output_dir = NULL) { 13 | 14 | if (is.null(ess_email)) ess_email <- get_email() 15 | # Check user is valid 16 | authenticate(ess_email) 17 | 18 | # Extract the ESS prefix with the round number 19 | ess_round <- string_extract(urls, "ESS[[:digit:]]") 20 | 21 | # The saving path is output if download is set to TRUE 22 | # otherwise tempdir() 23 | if (only_download && is.null(output_dir)) { 24 | stop("`output_dir` should be a valid directory") 25 | } 26 | 27 | alt_dir <- ifelse(only_download, output_dir, tempdir()) 28 | 29 | # create a temporary directory to unzip the files 30 | # if country is specified, create pre-folder with country 31 | # name 32 | if (!missing(country)) { 33 | td <- file.path(alt_dir, paste0("ESS_", country), ess_round) 34 | } else { 35 | td <- file.path(alt_dir, ess_round) 36 | } 37 | 38 | for (dire in td) dir.create(dire, recursive = TRUE, showWarnings = FALSE) 39 | # Loop throuch each url, round name and specific round folder, 40 | # download the data and save in the round-specific folder 41 | mapply(round_downloader, urls, ess_round, td) 42 | 43 | if (only_download) message("All files saved to ", normalizePath(output_dir)) 44 | 45 | td 46 | } 47 | 48 | # function authenticates the user with his/her email. 49 | authenticate <- function(ess_email) { 50 | 51 | if(missing(ess_email)) { 52 | stop( 53 | "`ess_email` parameter must be specified. Create an account at https://www.europeansocialsurvey.org/user/new" # nolint 54 | ) 55 | } 56 | 57 | if (nchar(ess_email) == 0) { 58 | stop( 59 | "The email address you provided is not associated with any registered user. Create an account at https://www.europeansocialsurvey.org/user/new" # nolint 60 | ) 61 | } 62 | 63 | # store your e-mail address in a list to be passed to the website 64 | values <- list(u = ess_email) 65 | 66 | url_login <- paste0(.global_vars$ess_website, .global_vars$path_login) 67 | # authenticate on the ess website 68 | authen <- httr::POST(url_login, 69 | body = values) 70 | 71 | check_authen <- 72 | safe_GET(url_login, 73 | query = values) 74 | 75 | authen_xml <- xml2::read_html(check_authen) 76 | error_node <- xml2::xml_find_all(authen_xml, '//p [@class="error"]') 77 | 78 | # If there is a log in error, stop an raise the text from the 79 | # class='error'. This should "Your email address is not regist 80 | # ered in the ESS website, or among those lines". 81 | if (length(error_node) != 0) { 82 | stop(xml2::xml_text(error_node), 83 | " Create an account at https://www.europeansocialsurvey.org/user/new") 84 | } 85 | 86 | } 87 | 88 | # Function downloads the url after authentification and saves 89 | # in the which_folder 90 | round_downloader <- function(each_url, which_round, which_folder) { # nocov start 91 | 92 | # Download the data 93 | message(paste("Downloading", which_round)) 94 | 95 | # round specific .zip file inside the round folder 96 | temp_download <- file.path(which_folder, paste0(which_round, ".zip")) 97 | 98 | current_file <- safe_GET(each_url, httr::progress()) 99 | 100 | # Write as a .zip file 101 | writeBin(httr::content(current_file, as = "raw") , temp_download) 102 | 103 | utils::unzip(temp_download, exdir = which_folder) 104 | } # nocov end 105 | 106 | # Safe getter 107 | safe_GET <- function(url, config = list(), ...) { # nocov start 108 | resp_conn <- httr::GET(url = url, config = config, ...) 109 | 110 | if (httr::status_code(resp_conn) > 300) { 111 | stop("We're unable to reach 'www.europeansocialsurvey.org'. Are you connected to the internet or is the website down?'") 112 | } 113 | 114 | resp_conn 115 | } # nocov end 116 | -------------------------------------------------------------------------------- /R/essurvey-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | #' @details Note that this package is for downloading data from the ESS survey. 3 | #' For analyzing the data, the user should consider the weights and sampling 4 | #' design of each country/round combination as well as sampling between rounds. 5 | #' For some examples, check out the work of Anthony Damico and Daniel Oberski 6 | #' \href{http://asdfree.com/european-social-survey-ess.html}{here}. For detailed 7 | #' examples on how to explore/download data using this package, visit the package website 8 | #' at \url{https://docs.ropensci.org/essurvey/} 9 | "_PACKAGE" 10 | -------------------------------------------------------------------------------- /R/import_countries.R: -------------------------------------------------------------------------------- 1 | #' Download integrated rounds separately for countries from the European Social 2 | #' Survey 3 | #' 4 | #' @param country a character of length 1 with the full name of the country. 5 | #' Use \code{\link{show_countries}} for a list of available countries. 6 | #' @param rounds a numeric vector with the rounds to download. See \code{\link{show_rounds}} 7 | #' for all available rounds. 8 | #' @param ess_email a character vector with your email, such as "your_email@email.com". 9 | #' If you haven't registered in the ESS website, create an account at 10 | #' \url{http://www.europeansocialsurvey.org/user/new}. A preferred method is to login 11 | #' through \code{\link{set_email}}. 12 | #' 13 | #' @param output_dir a character vector with the output directory in case you want to 14 | #' only download the files using \code{download_country}. Defaults to your working 15 | #' directory. This will be interpreted as a \strong{directory} and not a path with 16 | #' a file name. 17 | #' 18 | #' @param format the format from which to download the data. By default it is NULL for \code{import_*} functions and tries to read 'stata', 'spss' and 'sas' in the specific order. This can be useful if some countries don't have a particular format available. Alternatively, the user can specify the format which can either be 'stata', 'spss' or 'sas'. For the \code{download_*} functions it is set to 'stata' because the format should be specified before the downloading. When using \code{import_country} the data will be downloaded and read in the \code{format} specified. For \code{download_country}, the data is downloaded from the specified \code{format} (only 'spss' and 'stata' supported, see details). 19 | #' 20 | #' @details 21 | #' Use \code{import_country} to download specified rounds for a given country and 22 | #' import them to R. 23 | #' \code{import_all_cntrounds} will download all rounds for a given country by default 24 | #' and \code{download_country} will download rounds and save them in a specified 25 | #' \code{format} in the supplied directory. 26 | #' 27 | #' The \code{format} argument from \code{import_country} should not matter to the user 28 | #' because the data is read into R either way. However, different formats might have 29 | #' different handling of the encoding of some questions. This option was preserved 30 | #' so that the user 31 | #' can switch between formats if any encoding errors are found in the data. For more 32 | #' details see the discussion \href{https://github.com/ropensci/essurvey/issues/11}{here}. 33 | #' For this particular argument, 'sas' is not supported because the data formats have 34 | #' changed between ESS waves and separate formats require different functions to be 35 | #' read. To preserve parsimony and format errors between waves, the user should use 36 | #' 'spss' or 'stata'. 37 | #' 38 | #' @return for \code{import_country} if \code{length(rounds)} is 1, it returns a tibble 39 | #' with the latest version of that round. Otherwise it returns a list of \code{length(rounds)} 40 | #' containing the latest version of each round. For \code{download_country}, if 41 | #' \code{output_dir} is a valid directory, it returns the saved directories invisibly 42 | #' and saves all the rounds in the chosen \code{format} in \code{output_dir} 43 | #' @export 44 | #' 45 | #' @examples 46 | #' \dontrun{ 47 | #' 48 | #' set_email("your_email@email.com") 49 | #' 50 | #' # Get first three rounds for Denmark 51 | #' dk_three <- import_country("Denmark", 1:3) 52 | #' 53 | #' # Only download the files, this will return nothing 54 | #' 55 | #' temp_dir <- tempdir() 56 | #' 57 | #' download_country( 58 | #' "Turkey", 59 | #' rounds = c(2, 4), 60 | #' output_dir = temp_dir 61 | #' ) 62 | #' 63 | #' # By default, download_country downloads 'stata' files but 64 | #' # you can also download 'spss' or 'sas' files. 65 | #' 66 | #' download_country( 67 | #' "Turkey", 68 | #' rounds = c(2, 4), 69 | #' output_dir = temp_dir, 70 | #' format = 'spss' 71 | #' ) 72 | #' 73 | #' # If email is not registered at ESS website, error will arise 74 | #' uk_one <- import_country("United Kingdom", 5, "wrong_email@email.com") 75 | #' # Error in authenticate(ess_email) : 76 | #' # The email address you provided is not associated with any registered user. 77 | #' # Create an account at http://www.europeansocialsurvey.org/user/new 78 | #' 79 | #' # If selected rounds don't exist, error will arise 80 | #' 81 | #' czech_two <- import_country("Czech Republic", c(1, 22)) 82 | #' 83 | #' # Error in country_url(country, rounds) : 84 | #' # Only rounds ESS1, ESS2, ESS4, ESS5, ESS6, ESS7, ESS8 available 85 | #' # for Czech Republic 86 | #' } 87 | #' 88 | import_country <- function(country, rounds, ess_email = NULL, format = NULL) { 89 | 90 | stopifnot(is.character(country), length(country) > 0) 91 | stopifnot(is.numeric(rounds), length(rounds) > 0) 92 | 93 | if (!is.null(format) && format == "sas") { 94 | stop( 95 | "You cannot read SAS but only 'spss' and 'stata' files with this function. See ?import_country for more details" # nolint 96 | ) 97 | } 98 | 99 | urls <- country_url(country, rounds, format = format) 100 | 101 | dir_download <- download_format(country = country, 102 | urls, 103 | ess_email = ess_email) 104 | 105 | all_data <- read_format_data(dir_download, country) 106 | # Remove everything that was downloaded 107 | unlink(dir_download, recursive = TRUE, force = TRUE) 108 | 109 | # If only one dataframe, return that 110 | if (length(dir_download) == 1) all_data <- all_data[[1]] 111 | 112 | all_data 113 | } 114 | 115 | #' @rdname import_country 116 | #' @export 117 | import_all_cntrounds <- function(country, ess_email = NULL, format = NULL) { 118 | import_country(country, show_country_rounds(country), ess_email, format) 119 | } 120 | 121 | #' @rdname import_country 122 | #' @export 123 | download_country <- function(country, rounds, ess_email = NULL, 124 | output_dir = getwd(), format = "stata") { 125 | 126 | stopifnot(is.character(country), length(country) > 0) 127 | stopifnot(is.numeric(rounds), length(rounds) > 0) 128 | 129 | urls <- country_url(country, rounds, format = format) 130 | 131 | invisible( 132 | download_format(country = country, 133 | urls = urls, 134 | ess_email = ess_email, 135 | only_download = TRUE, 136 | output_dir = output_dir) 137 | ) 138 | } 139 | -------------------------------------------------------------------------------- /R/import_rounds.R: -------------------------------------------------------------------------------- 1 | #' Download integrated rounds from the European Social Survey 2 | #' 3 | #' @param rounds a numeric vector with the rounds to download. See \code{\link{show_rounds}} 4 | #' for all available rounds. 5 | #' @param ess_email a character vector with your email, such as "your_email@email.com". 6 | #' If you haven't registered in the ESS website, create an account at 7 | #' \url{http://www.europeansocialsurvey.org/user/new}. A preferred method is to login 8 | #' through \code{\link{set_email}}. 9 | #' 10 | #' @param output_dir a character vector with the output directory in case you want to only download the files using 11 | #' the \code{download_rounds}. Defaults to your working directory. This will be interpreted as 12 | #' a \strong{directory} and not a path with a file name. 13 | #' 14 | #' @param format the format from which to download the data. By default it is NULL for \code{import_*} functions and tries to read 'stata', 'spss' and 'sas' in the specific order. This can be useful if some countries don't have a particular format available. Alternatively, the user can specify the format which can either be 'stata', 'spss' or 'sas'. For the \code{download_*} functions it is set to 'stata' because the format should be specified before downloading. When using \code{import_country} the data will be downloaded and read in the \code{format} specified. For \code{download_country}, the data is downloaded from the specified \code{format} (only 'spss' and 'stata' supported, see details). 15 | #' 16 | #' @details 17 | #' Use \code{import_rounds} to download specified rounds and import them to R. 18 | #' \code{import_all_rounds} will download all rounds by default and \code{download_rounds} 19 | #' will download rounds and save them in a specified \code{format} in the supplied 20 | #' directory. 21 | #' 22 | #' The \code{format} argument from \code{import_rounds} should not matter to the user 23 | #' because the data is read into R either way. However, different formats might have 24 | #' different handling of the encoding of some questions. This option was preserved 25 | #' so that the user 26 | #' can switch between formats if any encoding errors are found in the data. For more 27 | #' details see the discussion \href{https://github.com/ropensci/essurvey/issues/11}{here}. 28 | #' For this particular argument in, 'sas' is not supported because the data formats have 29 | #' changed between ESS waves and separate formats require different functions to be 30 | #' read. To preserve parsimony and format errors between waves, the user should use 31 | #' 'spss' or 'stata'. 32 | #' 33 | #' @return for \code{import_rounds} if \code{length(rounds)} is 1, it returns a tibble 34 | #' with the latest version of that round. Otherwise it returns a list of \code{length(rounds)} 35 | #' containing the latest version of each round. For \code{download_rounds}, if 36 | #' \code{output_dir} is a valid directory, it returns the saved directories invisibly 37 | #' and saves all the rounds in the chosen \code{format} in \code{output_dir} 38 | #' @export 39 | #' 40 | #' @examples 41 | #' 42 | #' \dontrun{ 43 | #' 44 | #' set_email("your_email@email.com") 45 | #' 46 | #' # Get first three rounds 47 | #' three_rounds <- import_rounds(1:3) 48 | #' 49 | #' temp_dir <- tempdir() 50 | #' 51 | #' # Only download the files to output_dir, this will return nothing. 52 | #' download_rounds( 53 | #' rounds = 1:3, 54 | #' output_dir = temp_dir, 55 | #' ) 56 | #' 57 | #' # By default, download_rounds saves a 'stata' file. You can 58 | #' # also download 'spss' and 'sas' files. 59 | #' 60 | #' download_rounds( 61 | #' rounds = 1:3, 62 | #' output_dir = temp_dir, 63 | #' format = 'spss' 64 | #' ) 65 | #' 66 | #' # If rounds are repeated, will download only unique ones 67 | #' two_rounds <- import_rounds(c(1, 1)) 68 | #' 69 | #' # If email is not registered at ESS website, error will arise 70 | #' two_rounds <- import_rounds(c(1, 2), "wrong_email@email.com") 71 | #' 72 | #' # Error in authenticate(ess_email) : 73 | #' # The email address you provided is not associated with any registered user. 74 | #' # Create an account at https://www.europeansocialsurvey.org/user/new 75 | #' 76 | #' # If selected rounds don't exist, error will arise 77 | #' 78 | #' two_rounds <- import_rounds(c(1, 22)) 79 | #' # Error in round_url(rounds) : 80 | #' # ESS round 22 is not a available. Check show_rounds() 81 | #' } 82 | #' 83 | import_rounds <- function(rounds, ess_email = NULL, format = NULL) { 84 | 85 | stopifnot(is.numeric(rounds), length(rounds) > 0) 86 | if (!is.null(format) && format == "sas") { 87 | stop( 88 | "You cannot read SAS but only 'spss' and 'stata' files with this function. See ?import_rounds for more details") # nolint 89 | } 90 | 91 | urls <- round_url(rounds, format = format) 92 | 93 | dir_download <- download_format(ess_email = ess_email, 94 | urls = urls) 95 | 96 | all_data <- read_format_data(dir_download) 97 | # Remove everything that was downloaded 98 | unlink(dir_download, recursive = TRUE, force = TRUE) 99 | 100 | # If only one dataframe, return that 101 | all_data <- if (length(all_data) == 1) all_data[[1]] else all_data 102 | 103 | all_data 104 | } 105 | 106 | #' @rdname import_rounds 107 | #' @export 108 | import_all_rounds <- function(ess_email = NULL, format = NULL) { 109 | import_rounds(show_rounds(), ess_email, format) 110 | } 111 | 112 | #' @rdname import_rounds 113 | #' @export 114 | download_rounds <- function(rounds, 115 | ess_email = NULL, 116 | output_dir = getwd(), 117 | format = 'stata') { 118 | 119 | stopifnot(is.numeric(rounds), length(rounds) > 0) 120 | urls <- round_url(rounds, format = format) 121 | 122 | invisible(download_format(urls = urls, 123 | ess_email= ess_email, 124 | only_download = TRUE, 125 | output_dir = output_dir)) 126 | } 127 | -------------------------------------------------------------------------------- /R/read_format_data.R: -------------------------------------------------------------------------------- 1 | read_format_data <- function(dir_download, country = NULL, sddf = FALSE) { 2 | 3 | format_ext <- c(".dta", ".sav", ".por") 4 | # Get all paths from the format 5 | # I know list.files is vectorized, but list.files 6 | # sorts each results and I want to preserve round 7 | # orderings here. 8 | format_dirs <- vapply(dir_download, 9 | list.files, 10 | pattern = paste0(format_ext, "$", collapse = "|"), 11 | full.names = TRUE, 12 | FUN.VALUE = character(1)) 13 | 14 | # Read only the .dta/.sav/.por files 15 | dataset <- lapply(unname(format_dirs), function(.x) { 16 | 17 | # Use function to read the specified format 18 | format_read <- 19 | switch(file_ext(.x), 20 | "dta" = haven::read_dta, 21 | "por" = haven::read_sav, 22 | "sav" = haven::read_sav 23 | ) 24 | 25 | # Catch potential read errors 26 | # Reading some data such as SDDF data for France round 1 was 27 | # raising the message "Invalid time string (length=8): 0-------" 28 | # coming directly from Rcpp (https://github.com/WizardMac/ReadStat/search?q=Invalid+time+string&unscoped_q=Invalid+time+string) #nolintr 29 | # capture.output redirects the message to a tmpfile. 30 | utils::capture.output(dt <- try(format_read(.x), silent = TRUE), 31 | file = tempfile()) 32 | 33 | if ("try-error" %in% class(dt)) { 34 | 35 | if (!is_foreign_installed()) { 36 | stop("Package `foreign` is needed to read some SDDF data. Please install with install.packages(\"foreign\")") #nolintr 37 | } 38 | 39 | round_search <- basename(.x) 40 | rnd <- string_extract(round_search, "\\d", perl = TRUE) 41 | 42 | # Ask for a user report 43 | warning( 44 | paste("Round", 45 | rnd, 46 | if (is.null(country)) "" else paste("for", country), 47 | "was read with the `foreign` package rather than with ", 48 | "the `haven` package for compatibility reasons.\n", 49 | "Please report any issues at", 50 | "https://github.com/ropensci/essurvey/issues" 51 | ), 52 | call. = FALSE 53 | ) 54 | 55 | # Switch to `foreign` 56 | foreign_read <- 57 | switch(file_ext(.x), 58 | "dta" = foreign::read.dta, 59 | "por" = read_foreign_spss_partial(sddf = sddf), 60 | "sav" = read_foreign_spss_partial(sddf = sddf) 61 | ) 62 | # Read with `foreign` (should never fail) 63 | dt <- 64 | suppress_all( 65 | foreign_read(.x) 66 | ) 67 | } 68 | 69 | # Always a return a tibble with lowercase variable names 70 | tibble::as_tibble(dt, .name_repair = tolower) 71 | 72 | }) 73 | 74 | dataset 75 | 76 | } 77 | 78 | read_foreign_spss_partial <- function(sddf = FALSE, ...) { 79 | function(x, ...) { 80 | sddf <- get("sddf", envir = environment()) 81 | foreign::read.spss(file = x, 82 | to.data.frame = TRUE, 83 | stringsAsFactors = FALSE, 84 | use.value.labels = if (sddf) FALSE else TRUE, 85 | ... 86 | ) 87 | 88 | } 89 | } 90 | 91 | # Taken from tools::file_ext 92 | file_ext <- function(x) { 93 | pos <- regexpr("\\.([[:alnum:]]+)$", x) 94 | ifelse(pos > -1L, substring(x, pos + 1L), "") 95 | } 96 | 97 | 98 | is_foreign_installed <- function() { 99 | requireNamespace("foreign", quietly = TRUE) 100 | } 101 | 102 | suppress_all <- function(x) suppressMessages(suppressWarnings(x)) 103 | 104 | string_extract <- function(string, pattern, ...) { 105 | regmatches(string, regexpr(pattern, string, ...)) 106 | } 107 | 108 | read_sddf_data <- function(dir_download, country) { 109 | all_data <- read_format_data(dir_download, country, sddf = TRUE) 110 | 111 | # Search for the 2 letter code because we need to subset 112 | # from the integrated SDDF for the current country 113 | country_code <- country_lookup[country] 114 | 115 | # Subset the selected country from the integrated late rounds 116 | all_data <- lapply(all_data, function(x) x[x$cntry == country_code, ]) 117 | 118 | all_data 119 | } 120 | -------------------------------------------------------------------------------- /R/recode_missings.R: -------------------------------------------------------------------------------- 1 | #' Recode pre-defined missing values as NA 2 | #' 3 | #' This function is not needed any more, please see the details section. 4 | #' 5 | #' Data from the European Social Survey is always accompanied by a script 6 | #' that recodes the categories 'Not applicable', 'Refusal', 'Don't Know', 7 | #' 'No answer' and 'Not available' to missing. This function recodes 8 | #' these categories to NA 9 | #' 10 | #' @param ess_data data frame or \code{\link[tibble]{tibble}} with data from the 11 | #' European Social Survey. This data frame should come either 12 | #' from \code{\link{import_rounds}}, \code{\link{import_country}} or read with 13 | #' \code{\link[haven]{read_dta}} or \code{\link[haven]{read_spss}}. This is the case because it 14 | #' identifies missing values using \code{\link[haven]{labelled}} classes. 15 | #' @param missing_codes a character vector with values 'Not applicable', 16 | #' 'Refusal', 'Don't Know', 'No answer' or 'Not available'. By default 17 | #' all values are chosen. Note that the wording is case sensitive. 18 | #' 19 | #' @return 20 | #' The same data frame or \code{\link[tibble]{tibble}} but with values 'Not applicable', 21 | #' 'Refusal', 'Don't Know', 'No answer' and 'Not available' recoded 22 | #' as NA. 23 | #' 24 | #' @details 25 | #' 26 | #' The European Social Survey now provides these values recoded automatically 27 | #' in Stata data files. These missing categories are now read as missing values 28 | #' by \code{\link[haven]{read_dta}}, reading the missing categories correctly from Stata.For an example on how these values are coded, see \href{https://github.com/ropensci/essurvey/issues/35}{here}. 29 | #' 30 | #' Old details: 31 | #' 32 | #' When downloading data directly from the European Social Survey's website, 33 | #' the downloaded .zip file contains a script that recodes some categories 34 | #' as missings in Stata and SPSS formats. 35 | #' 36 | #' For recoding numeric variables \code{recode_numeric_missings} 37 | #' uses the labels provided by the \code{\link[haven]{labelled}} 38 | #' class to delete the labels matched in \code{missing_codes}. For the 39 | #' character variables matching is done with the underlying number assigned to 40 | #' each category, namely 6, 7, 8, 9 and 9 for 'Not applicable', Refusal', 41 | #' 'Don't Know', No answer' and 'Not available'. 42 | #' 43 | #' The functions are a direct translation of the Stata script that comes 44 | #' along when downloading one of the rounds. The Stata script is the same 45 | #' for all rounds and all countries, meaning that these functions work 46 | #' for all rounds. 47 | #' 48 | #' @export 49 | #' 50 | #' @examples 51 | #' \dontrun{ 52 | #' seven <- import_rounds(7, your_email) 53 | #' 54 | #' attr(seven$tvtot, "labels") 55 | #' mean(seven$tvtot, na.rm = TRUE) 56 | #' 57 | #' names(table(seven$lnghom1)) 58 | #' # First three are actually missing values 59 | #' 60 | #' seven_recoded <- recode_missings(seven) 61 | #' 62 | #' attr(seven_recoded$tvtot, "labels") 63 | #' # All missings have been removed 64 | #' mean(seven_recoded$tvtot, na.rm = TRUE) 65 | #' 66 | #' names(table(seven_recoded$lnghom1)) 67 | #' # All missings have been removed 68 | #' 69 | #' # If you want to operate on specific variables 70 | #' # you can use other recode_*_missing 71 | #' 72 | #' seven$tvtot <- recode_numeric_missing(seven$tvtot) 73 | #' 74 | #' # Recode only 'Don't know' and 'No answer' to missing 75 | #' seven$tvpol <- recode_numeric_missing(seven$tvpol, c("Don't know", "No answer")) 76 | #' 77 | #' 78 | #' # The same can be done with recode_strings_missing 79 | #' } 80 | #' 81 | recode_missings <- function(ess_data, missing_codes) { 82 | 83 | stopifnot(is.data.frame(ess_data)) 84 | 85 | labelled_numerics <- vapply(ess_data, is_labelled_numeric, logical(1)) 86 | character_vars <- vapply(ess_data, is.character, logical(1)) 87 | 88 | ess_data[labelled_numerics] <- lapply(ess_data[labelled_numerics], 89 | recode_numeric_missing, 90 | missing_codes) 91 | 92 | ess_data[character_vars] <- lapply(ess_data[character_vars], 93 | recode_strings_missing, 94 | missing_codes) 95 | ess_data 96 | } 97 | 98 | #' @param x a \code{\link[haven]{labelled}} numeric 99 | #' 100 | #' @rdname recode_missings 101 | #' @export 102 | recode_numeric_missing <- function(x, missing_codes) { 103 | stopifnot(is_labelled_numeric(x)) 104 | 105 | if (!missing(missing_codes)) { 106 | validate_missing_codes(missing_codes) 107 | } else { 108 | missing_codes <- .global_vars$all_codes 109 | } 110 | 111 | labels <- attr(x, "labels") 112 | missings <- names(labels) %in% missing_codes 113 | attr(x, "labels") <- labels[!missings] 114 | x[x %in% labels[missings]] <- NA 115 | x 116 | } 117 | 118 | #' @param y a character vector 119 | #' @rdname recode_missings 120 | #' @export 121 | recode_strings_missing <- function(y, missing_codes) { 122 | stopifnot(is.character(y)) 123 | 124 | if (!missing(missing_codes)) { 125 | # Check that all supplied are valid missing codes 126 | validate_missing_codes(missing_codes) 127 | # Identify the ones that match 128 | which_are <- .global_vars$all_codes %in% missing_codes 129 | # Grab the numeric recode and select unique 130 | missing_codes <- unique(names(.global_vars$all_codes[which_are])) 131 | } else { 132 | missing_codes <- unique(names(.global_vars$all_codes)) 133 | } 134 | 135 | values_to_recode <- paste0(missing_codes, collapse = "") 136 | search_expr <- paste0("^([", values_to_recode,"])\\1{1,}$") 137 | missings <- grepl(search_expr, y) 138 | y[missings] <- NA 139 | y 140 | } 141 | 142 | validate_missing_codes <- function(x) { 143 | available <- x %in% .global_vars$all_codes 144 | if (!all(available)) { 145 | stop("Codes not available: ", 146 | paste0(x[!available], collapse = ", ")) 147 | } 148 | } 149 | 150 | is_labelled_numeric <- function(x) { 151 | haven::is.labelled(x) && is.numeric(x) 152 | } 153 | -------------------------------------------------------------------------------- /R/set_email.R: -------------------------------------------------------------------------------- 1 | #' Save your ESS email as an environment variable 2 | #' 3 | #' @param ess_email a character string with your registered email. 4 | #' 5 | #' @details You should only run \code{set_email()} once and every \code{import_} and \code{download_} function 6 | #' should work fine. Make sure your email is registered at 7 | #' \url{http://www.europeansocialsurvey.org/} before setting the email. 8 | #' 9 | #' @export 10 | #' 11 | #' @examples 12 | #' 13 | #' \dontrun{ 14 | #' set_email("my_registered@email.com") 15 | #' 16 | #' import_rounds(1) 17 | #' } 18 | #' 19 | set_email <- function(ess_email) { 20 | Sys.setenv("ESS_EMAIL" = ess_email) 21 | } 22 | 23 | get_email <- function() { 24 | ess_email <- Sys.getenv("ESS_EMAIL") 25 | if (ess_email == "") { 26 | stop("No email account set as environment variable. Use set_email to set your email.") 27 | } 28 | ess_email 29 | } 30 | -------------------------------------------------------------------------------- /R/show_any_rounds.R: -------------------------------------------------------------------------------- 1 | #' Return countries that participated in \strong{all} of the specified rounds. 2 | #' 3 | #' @param rounds A numeric vector specifying the rounds from which to return the countries. 4 | #' Use \code{\link{show_rounds}}for a list of available rounds. 5 | #' @param participate A logical that controls whether to show participating countries in that/those 6 | #' rounds or countries that didn't participate. Set to \code{TRUE} by default. 7 | #' 8 | #' @details \code{show_rounds_country} returns the countries that participated in 9 | #' \strong{all} of the specified rounds. That is, \code{show_rounds_country(1:2)} 10 | #' will return countries that participated both in round 1 and round 2. Conversely, 11 | #' if \code{participate = FALSE} it will return the countries that did not 12 | #' participate in \strong{both} round 1 and round 2. 13 | #' 14 | #' @return A character vector with the country names 15 | #' @export 16 | #' 17 | #' @examples 18 | #' 19 | #' \dontrun{ 20 | #' 21 | #' # Return countries that participated in round 2 22 | #' 23 | #' show_rounds_country(2) 24 | #' 25 | #' # Return countries that participated in all rounds 26 | #' 27 | #' show_rounds_country(1:8) 28 | #' 29 | #' # Return countries that didn't participate in the first three rounds 30 | #' 31 | #' show_rounds_country(1:3, participate = FALSE) 32 | #' 33 | #' } 34 | show_rounds_country <- function(rounds, participate = TRUE) { 35 | 36 | check_rounds(rounds) 37 | 38 | # Obtain the country list with years that participated 39 | module_list <- table_to_list(.global_vars$ess_website, 40 | .global_vars$country_index) 41 | 42 | # Because names get messed up when turning module_list into a df 43 | # here I save the pretty country names 44 | country_names <- names(module_list) 45 | 46 | # Turn the list into a lookupable matrix 47 | country_rnd_subset <- t(data.frame(module_list)) 48 | 49 | # create all() function depending on whether the user wants the participating 50 | # or non-participating countries. The +1 is so that if its TRUE, +1 will 51 | # return the second argument, and 0+1 the first arguments 52 | new_all <- switch(as.numeric(participate) + 1, function(x) !all(x), all) 53 | 54 | # Take only the rounds specified 55 | subset_df <- country_rnd_subset[, rounds, drop = FALSE] 56 | 57 | # Check which countries participates in all rounds 58 | which_cnts <- vapply(seq_len(nrow(subset_df)), 59 | function(x) new_all(subset_df[x, ]), 60 | FUN.VALUE = logical(1)) 61 | 62 | country_names[which_cnts] 63 | } 64 | 65 | #' Return available rounds for a country in the European Social Survey 66 | #' 67 | #' @param country A character of length 1 with the full name of the country. 68 | #' Use \code{\link{show_countries}}for a list of available countries. 69 | #' 70 | #' @return numeric vector with available rounds for \code{country} 71 | #' @export 72 | #' 73 | #' @examples 74 | #' 75 | #' \dontrun{ 76 | #' 77 | #' show_country_rounds("Spain") 78 | #' 79 | #' show_country_rounds("Turkey") 80 | #' 81 | #' } 82 | #' 83 | show_country_rounds <- function(country) { 84 | 85 | # Check if country is present 86 | check_country(country) 87 | 88 | show_any_rounds(country, .global_vars$country_index) 89 | 90 | } 91 | 92 | #' Return available rounds for a theme in the European Social Survey 93 | #' 94 | #' This function returns the available rounds for any theme from 95 | #' \code{\link{show_themes}}. However, contrary to \code{\link{show_country_rounds}} 96 | #' themes can not be downloaded as separate datasets. This and the 97 | #' \code{\link{show_themes}} function serve purely for informative purposes. 98 | #' 99 | #' 100 | #' @param theme A character of length 1 with the full name of the theme. 101 | #' Use \code{\link{show_themes}}for a list of available themes. 102 | #' 103 | #' @return numeric vector with available rounds for \code{country} 104 | #' @export 105 | #' 106 | #' @examples 107 | #' 108 | #' \dontrun{ 109 | #' chosen_theme <- show_themes()[3] 110 | #' 111 | #' # In which rounds was the topic of 'Democracy' asked? 112 | #' show_theme_rounds(chosen_theme) 113 | #' 114 | #' # And politics? 115 | #' show_theme_rounds("Politics") 116 | #' 117 | #' } 118 | #' 119 | show_theme_rounds <- function(theme) { 120 | 121 | check_theme(theme) 122 | 123 | show_any_rounds(theme, .global_vars$theme_index) 124 | } 125 | 126 | # Generic function to grab the rounds of any module 127 | show_any_rounds <- function(module, module_index) { 128 | 129 | # Get unique country to avoid repetitions 130 | module <- sort(unique(module)) 131 | 132 | # Get the table for each module-round combination as a list 133 | module_list <- table_to_list(.global_vars$ess_website, module_index) 134 | 135 | # The list is easy to subset, so just subset the available module 136 | # from the list and then subset the available rounds from the 137 | # global variable 138 | available_rounds <- show_rounds()[module_list[[module]]] 139 | 140 | available_rounds 141 | } 142 | 143 | 144 | # This is the workhorse of the show_* funs. 145 | # Function takes the esswebsite and the module index 146 | # and scrapes the table from the index and returns a list 147 | # where every slot is a country and contains a logical 148 | # for which rounds are available for every country 149 | table_to_list <- function(ess_website, module_index) { # nocov start 150 | download_page <- safe_GET(paste0(ess_website, module_index)) 151 | 152 | # Extract the table in xml format 153 | table_rounds_xml <- rvest::html_node(xml2::read_html(download_page), "table") 154 | 155 | # Some of these tables have a shaded dot which means that the data will be 156 | # available in the future but it is not currently available. It's best 157 | # if we don't show those dots at all because it confuses the users ( 158 | # and raises an error) thinking that the round is there (at least 159 | # when looking at it from R). 160 | 161 | # Here I search for the .//span tag which is the tag that gives the dots 162 | # shaded color. could be a tag somewhere else in the document 163 | # that's why I set .// so that it searchers below the current node, 164 | # that is, only on the table. 165 | 166 | # remove those nodes 167 | xml2::xml_remove(xml2::xml_find_all(table_rounds_xml, ".//span"), free = TRUE) 168 | 169 | # Turn the xml table into a df. First col is country names and 170 | # all other are rounds 171 | dirty_table_df <- rvest::html_table(table_rounds_xml, header = TRUE) 172 | 173 | # Recode the empty cells to FALSE and others to TRUE 174 | dirty_table_df[, -1] <- 175 | lapply(dirty_table_df[, -1], 176 | function(x) ifelse(x == "" | is.na(x), FALSE, TRUE) 177 | ) 178 | 179 | # Returns a list for every country containing the 180 | # logical for which rounds they were present. This 181 | # is better than a df because subsetting would be 182 | # too dirty to subset country rows. 183 | list_rounds <- split(dirty_table_df[, -1], dirty_table_df[[1]]) 184 | 185 | list_rounds <- lapply(list_rounds, as.logical) 186 | 187 | list_rounds 188 | } # nocov end 189 | -------------------------------------------------------------------------------- /R/show_sddf_cntrounds.R: -------------------------------------------------------------------------------- 1 | #' Return available SDDF rounds for a country in the European Social Survey 2 | #' 3 | #' @param country A character of length 1 with the full name of the country. 4 | #' Use \code{\link{show_countries}} for a list of available countries. 5 | #' 6 | #' @param ess_email a character vector with your email, such as "your_email@email.com". 7 | #' If you haven't registered in the ESS website, create an account at 8 | #' \url{http://www.europeansocialsurvey.org/user/new}. A preferred method is to login 9 | #' through \code{\link{set_email}}. 10 | #' 11 | #' @details 12 | #' SDDF data are the equivalent weight data used to analyze the European Social Survey 13 | #' properly. For more information, see the details section of \code{\link{import_sddf_country}}. 14 | #' As an exception to the \code{show_*} family of functions, \code{show_sddf rounds} 15 | #' needs your ESS email to check which rounds are available. Be sure to add it 16 | #' with \code{\link{set_email}}. 17 | #' 18 | #' 19 | #' @return numeric vector with available rounds for \code{country} 20 | #' @export 21 | #' 22 | #' @examples 23 | #' 24 | #' \dontrun{ 25 | #' set_email("your_email@email.com") 26 | #' 27 | #' show_sddf_cntrounds("Spain") 28 | #' } 29 | #' 30 | show_sddf_cntrounds <- function(country, ess_email = NULL) { 31 | check_country(country) 32 | 33 | # Returns the chosen countries html that contains 34 | # the links to all rounds. 35 | country_round_html <- extract_country_html(country, 36 | .global_vars$country_index) 37 | 38 | # Go deeper in the node to grab that countries url to the rounds 39 | country_node <- xml2::xml_find_all(country_round_html, "//ul //li //a") 40 | 41 | # Here we have all href from the website 42 | country_href <- xml2::xml_attrs(country_node, "href") 43 | 44 | incomplete_links <- 45 | sort( 46 | grep("^/download.html\\?file=ESS[0-9]{1,}_[A-Z]{1,2}_SDDF(.*)[0-9]{4, }$", 47 | country_href, 48 | value = TRUE) 49 | ) 50 | 51 | # Extract round numbers 52 | early_rounds <- 53 | as.numeric( 54 | string_extract(incomplete_links, "[0-9]{1,2}") 55 | ) 56 | 57 | # Extracting late rounds 58 | all_rounds <- show_rounds() 59 | late_rounds <- all_rounds[all_rounds > 6] 60 | 61 | # Extract country-specific late SDDF rounds 62 | url_download <- grab_url_sddf_late_rounds(late_rounds, format = NULL) 63 | 64 | late_rounds <- 65 | as.numeric( 66 | gsub("ESS", "", string_extract(url_download, "ESS[0-9{1,2}]")) 67 | ) 68 | 69 | # Here I thought I might've introduced a bug because 70 | # if I run show_sddf_cntrounds("Spain") and then 71 | # show_sddf_cntrounds("Italy") then I thought that 72 | # because the sddf_laterounds_dir was already created and existed 73 | # for Spain, it WON'T download the data files for Italy. The thing 74 | # is that it doesn't matter because late rounds are integrated for 75 | # all countries, so I just reread the Spanish downloaded one 76 | # and filter for ITALY. 77 | 78 | if (!all(dir.exists(.global_vars$sddf_laterounds_dir))) { 79 | 80 | utils::capture.output( 81 | dir_downloads <- 82 | suppress_all( 83 | download_format(urls = url_download, 84 | ess_email = ess_email, 85 | only_download = TRUE, 86 | output_dir = file.path(tempdir(), "ESS_SDDF") 87 | ) 88 | ), 89 | file = tempfile() 90 | ) 91 | 92 | .global_vars$sddf_laterounds_dir <- dir_downloads 93 | } 94 | 95 | late_data <- 96 | suppress_all( 97 | read_sddf_data(.global_vars$sddf_laterounds_dir, 98 | country) 99 | ) 100 | 101 | nrow_data <- vapply(late_data, nrow, FUN.VALUE = numeric(1)) 102 | 103 | c(early_rounds, late_rounds[nrow_data > 0]) 104 | } 105 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | github_document: 4 | html_preview: false 5 | --- 6 | ```{r, echo = FALSE} 7 | knitr::opts_chunk$set( 8 | collapse = TRUE, 9 | comment = "#>", 10 | fig.path = "README-", 11 | eval = FALSE 12 | ) 13 | options(tibble.print_min = 5, tibble.print_max = 5) 14 | ``` 15 | 16 | ## essurvey 17 | 18 | [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/essurvey)](https://cran.r-project.org/package=essurvey) 19 | [![R build status](https://github.com/ropensci/essurvey/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/essurvey/actions) 20 | [![Coverage status](https://codecov.io/gh/ropensci/essurvey/branch/master/graph/badge.svg)](https://codecov.io/github/ropensci/essurvey?branch=master) 21 | [![rOpensci_Badge](https://badges.ropensci.org/201_status.svg)](https://github.com/ropensci/software-review/issues/201) 22 | 23 | 24 | ## Description 25 | 26 | 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](http://www.europeansocialsurvey.org/about/). 27 | 28 | 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. 29 | 30 | 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](https://docs.ropensci.org/essurvey/) for more detailed examples of the `essurvey` package. 31 | 32 | ## Installation 33 | 34 | You can install and load the development version with these commands: 35 | 36 | ```{r} 37 | # install.packages("devtools") in case you don't have it 38 | devtools::install_github("ropensci/essurvey") 39 | ``` 40 | 41 | or the stable version with: 42 | 43 | ```{r} 44 | install.packages("essurvey") 45 | ``` 46 | 47 | ## Usage 48 | 49 | First, you need to register at the ESS website, in case you haven't. Please visit the [register](http://www.europeansocialsurvey.org/user/new) section from the ESS website. If your email is not registered at their website, an error will be raised prompting you to go register. 50 | 51 | Set your valid email as en environment variable. 52 | 53 | ```{r} 54 | set_email("your@email.com") 55 | ``` 56 | 57 | To explore which rounds/countries are present in the ESS use the `show_*()` family of functions. 58 | 59 | ```{r, eval = TRUE} 60 | library(essurvey) 61 | show_countries() 62 | ``` 63 | 64 | To download the first round to use in R: 65 | 66 | ```{r} 67 | one_round <- import_rounds(1) 68 | ``` 69 | 70 | 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). 71 | 72 | Use `recode_missings` to recode all values automatically. 73 | 74 | ```{r} 75 | library(tidyverse) 76 | 77 | one_round <- 78 | import_rounds(1) %>% 79 | recode_missings() 80 | ``` 81 | 82 | 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. 83 | 84 | ```{r} 85 | five_rounds <- import_rounds(1:5) 86 | ``` 87 | 88 | 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. 89 | 90 | You can check the available rounds with `show_rounds()` because if you supply a non existent round, the function will return an error. 91 | 92 | ```{r} 93 | two_rounds <- import_rounds(c(1, 22)) 94 | #> Error in round_url(rounds) : 95 | #> ESS round 22 is not a available. Check show_rounds() 96 | ``` 97 | 98 | Alternatively, you can download all available rounds with `import_all_rounds()`. 99 | 100 | You can also download rounds by country: 101 | 102 | ```{r} 103 | dk_two <- import_country("Denmark", 1:2) 104 | ``` 105 | 106 | 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. 107 | 108 | 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](http://asdfree.com/european-social-survey-ess.html). 109 | 110 | ## Stata, SPSS and SAS users 111 | 112 | 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. 113 | ```{r} 114 | download_rounds(c(1, 2), 115 | output_dir = "my/new/directory", 116 | format = 'spss') 117 | ``` 118 | 119 | 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. 120 | 121 | --- 122 | 123 | Please note that this project is released with a [Contributor Code of Conduct](https://docs.ropensci.org/essurvey/CONDUCT.html). By participating in this project you agree to abide by its terms. 124 | 125 | [![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org) 126 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## essurvey 3 | 4 | [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/essurvey)](https://cran.r-project.org/package=essurvey) 5 | [![R build 6 | status](https://github.com/ropensci/essurvey/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/essurvey/actions) 7 | [![Coverage 8 | status](https://codecov.io/gh/ropensci/essurvey/branch/master/graph/badge.svg)](https://codecov.io/github/ropensci/essurvey?branch=master) 9 | [![rOpensci\_Badge](https://badges.ropensci.org/201_status.svg)](https://github.com/ropensci/software-review/issues/201) 10 | 11 | ## Description 12 | 13 | The European Social Survey (ESS) is an academically driven 14 | cross-national survey that has been conducted across Europe since its 15 | establishment in 2001. Every two years, face-to-face interviews are 16 | conducted with newly selected, cross-sectional samples. The survey 17 | measures the attitudes, beliefs and behavior patterns of diverse 18 | populations in more than thirty nations. Taken from the [ESS 19 | website](http://www.europeansocialsurvey.org/about/). 20 | 21 | Note: The `essurvey` package was originally called `ess`. Since 22 | `essurvey 1.0.0` all `ess_*` functions have been deprecated in favor of 23 | the `import_*` and `download_*` functions. Also, versions less than and 24 | including `essurvey 1.0.1` returned wrong countries. Please install the 25 | latest CRAN/Github version. 26 | 27 | The `essurvey` package is designed to download the ESS data as easily as 28 | possible. It has a few helper functions to download rounds (a term 29 | synonym to waves to denote the same survey in different time points), 30 | rounds for a selected country and to show which rounds/countries are 31 | available. Check out the vignette and other documentation in the 32 | [package’s website](https://docs.ropensci.org/essurvey/) for more 33 | detailed examples of the `essurvey` package. 34 | 35 | ## Installation 36 | 37 | You can install and load the development version with these commands: 38 | 39 | ``` r 40 | # install.packages("devtools") in case you don't have it 41 | devtools::install_github("ropensci/essurvey") 42 | ``` 43 | 44 | or the stable version with: 45 | 46 | ``` r 47 | install.packages("essurvey") 48 | ``` 49 | 50 | ## Usage 51 | 52 | First, you need to register at the ESS website, in case you haven’t. 53 | Please visit the 54 | [register](http://www.europeansocialsurvey.org/user/new) section from 55 | the ESS website. If your email is not registered at their website, an 56 | error will be raised prompting you to go register. 57 | 58 | Set your valid email as en environment variable. 59 | 60 | ``` r 61 | set_email("your@email.com") 62 | ``` 63 | 64 | To explore which rounds/countries are present in the ESS use the 65 | `show_*()` family of functions. 66 | 67 | ``` r 68 | library(essurvey) 69 | show_countries() 70 | #> [1] "Albania" "Austria" "Belgium" 71 | #> [4] "Bulgaria" "Croatia" "Cyprus" 72 | #> [7] "Czechia" "Denmark" "Estonia" 73 | #> [10] "Finland" "France" "Germany" 74 | #> [13] "Greece" "Hungary" "Iceland" 75 | #> [16] "Ireland" "Israel" "Italy" 76 | #> [19] "Kosovo" "Latvia" "Lithuania" 77 | #> [22] "Luxembourg" "Montenegro" "Netherlands" 78 | #> [25] "Norway" "Poland" "Portugal" 79 | #> [28] "Romania" "Russian Federation" "Serbia" 80 | #> [31] "Slovakia" "Slovenia" "Spain" 81 | #> [34] "Sweden" "Switzerland" "Turkey" 82 | #> [37] "Ukraine" "United Kingdom" 83 | ``` 84 | 85 | To download the first round to use in R: 86 | 87 | ``` r 88 | one_round <- import_rounds(1) 89 | ``` 90 | 91 | This will return a data frame containing the first round. Typically, the 92 | European Social Survey data files comes with a script that recodes 93 | missing values to `NA` for different programs (Stata, SPSS, SAS). 94 | 95 | Use `recode_missings` to recode all values automatically. 96 | 97 | ``` r 98 | library(tidyverse) 99 | 100 | one_round <- 101 | import_rounds(1) %>% 102 | recode_missings() 103 | ``` 104 | 105 | See the package vignette for greater detail or see the help page with 106 | `?recode_missings`. You can also download several rounds by supplying 107 | the number of rounds. 108 | 109 | ``` r 110 | five_rounds <- import_rounds(1:5) 111 | ``` 112 | 113 | This will download all latest versions of rounds 1 through 5 and return 114 | a list of length 5 with each round as a data frame inside the list. 115 | 116 | You can check the available rounds with `show_rounds()` because if you 117 | supply a non existent round, the function will return an error. 118 | 119 | ``` r 120 | two_rounds <- import_rounds(c(1, 22)) 121 | #> Error in round_url(rounds) : 122 | #> ESS round 22 is not a available. Check show_rounds() 123 | ``` 124 | 125 | Alternatively, you can download all available rounds with 126 | `import_all_rounds()`. 127 | 128 | You can also download rounds by country: 129 | 130 | ``` r 131 | dk_two <- import_country("Denmark", 1:2) 132 | ``` 133 | 134 | Use `show_countries()` to see available countries and 135 | `show_country_rounds("Denmark")` to see available rounds for chosen 136 | country. Alternatively, use `import_all_cntrounds()` to download all 137 | available rounds of a country. 138 | 139 | You should be be aware that data from the ESS survey should by analyzed 140 | by taking into consideration the sampling and weights of the survey. A 141 | useful example comes from the work of Anthony Damico and Daniel Oberski 142 | [here](http://asdfree.com/european-social-survey-ess.html). 143 | 144 | ## Stata, SPSS and SAS users 145 | 146 | I’m quite aware that most ESS users don’t know R, that is why the 147 | package also allows to download the data in Stata, SPSS or SAS format 148 | with just one line of code. Instead of the `import_*` functions, use the 149 | `download_*` functions. 150 | 151 | ``` r 152 | download_rounds(c(1, 2), 153 | output_dir = "my/new/directory", 154 | format = 'spss') 155 | ``` 156 | 157 | This will save the ESS rounds into separate folders and unzip them in 158 | the specified directory (if you want to know your current directory, 159 | type `getwd()`). This works the same way for `download_country()`. Be 160 | aware that if you download the files manually you should read them into 161 | R with the `haven` package for all `essurvey` related functions to work. 162 | 163 | ----- 164 | 165 | Please note that this project is released with a [Contributor Code of 166 | Conduct](https://docs.ropensci.org/essurvey/CONDUCT.html). By 167 | participating in this project you agree to abide by its terms. 168 | 169 | [![ropensci\_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org) 170 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE the "init" and "install" sections below 2 | 3 | # Download script file from GitHub 4 | init: 5 | ps: | 6 | $ErrorActionPreference = "Stop" 7 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 8 | Import-Module '..\appveyor-tool.ps1' 9 | 10 | install: 11 | ps: Bootstrap 12 | 13 | cache: 14 | - C:\RLibrary 15 | 16 | # Adapt as necessary starting from here 17 | 18 | environment: 19 | PKGTYPE: win.binary 20 | NOT_CRAN: true 21 | 22 | build_script: 23 | - travis-tool.sh install_deps 24 | 25 | test_script: 26 | - travis-tool.sh run_tests 27 | 28 | on_failure: 29 | - 7z a failure.zip *.Rcheck\* 30 | - appveyor PushArtifact failure.zip 31 | 32 | artifacts: 33 | - path: '*.Rcheck\**\*.log' 34 | name: Logs 35 | 36 | - path: '*.Rcheck\**\*.out' 37 | name: Logs 38 | 39 | - path: '*.Rcheck\**\*.fail' 40 | name: Logs 41 | 42 | - path: '*.Rcheck\**\*.Rout' 43 | name: Logs 44 | 45 | - path: '\*_*.tar.gz' 46 | name: Bits 47 | 48 | - path: '\*_*.zip' 49 | name: Bits 50 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | patch: 10 | default: 11 | target: auto 12 | threshold: 1% 13 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Test environments 2 | - local Ubuntu 20.0.0 LTS, 4.0.3 3 | - Windows Server 2019 (r-release) 4 | - Mac OS X (r-release) 5 | - Ubuntu 20.04.2 (r-release) 6 | - Ubuntu 20.04.2 (r-devel) 7 | 8 | 9 | ## R CMD check results 10 | 11 | - - 0 errors ✔ | 0 warnings ✔ | 0 notes ✔ 12 | 13 | ## Reverse dependencies 14 | 15 | There are currently no downstream dependencies for this package. 16 | 17 | --- 18 | 19 | Fixed bugs from the library. Standard patch release. 20 | 21 | - All tests are run weekly on Github Actions, which are available at https://github.com/ropensci/essurvey/action 22 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • essurvey 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 |
24 |
73 | 74 | 75 | 76 | 77 |
78 |
79 | 82 | 83 | Content not found. Please use links in the navbar. 84 | 85 |
86 | 87 | 91 | 92 |
93 | 94 | 95 | 96 |
100 | 101 |
102 |

103 |

Site built with pkgdown 2.0.1.

104 |
105 | 106 |
107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /docs/CONDUCT.html: -------------------------------------------------------------------------------- 1 | 2 | Contributor Code of Conduct • essurvey 6 | 7 | 8 |
9 |
50 | 51 | 52 | 53 |
54 |
55 | 58 | 59 |
60 | 61 |

As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

62 |

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.

63 |

Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.

64 |

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.

65 |

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.

66 |

This Code of Conduct is adapted from the Contributor Covenant (http:contributor-covenant.org), version 1.0.0, available at http://contributor-covenant.org/version/1/0/0/

67 |
68 | 69 |
70 | 71 | 74 | 75 |
76 | 77 | 78 | 79 |
82 | 83 |
84 |

Site built with pkgdown 2.0.1.

85 |
86 | 87 |
88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | License • essurvey 6 | 7 | 8 |
9 |
50 | 51 | 52 | 53 |
54 |
55 | 58 | 59 |
YEAR: 2018
60 | COPYRIGHT HOLDER: Jorge Cimentada
61 | 
62 | 63 |
64 | 65 | 68 | 69 |
70 | 71 | 72 | 73 |
76 | 77 |
78 |

Site built with pkgdown 2.0.1.

79 |
80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /docs/LICENSE.html: -------------------------------------------------------------------------------- 1 | 2 | MIT License • essurvey 6 | 7 | 8 |
9 |
50 | 51 | 52 | 53 |
54 |
55 | 58 | 59 |
60 | 61 |

Copyright (c) 2018 Jorge Cimentada

62 |

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

63 |

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

64 |

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

65 |
66 | 67 |
68 | 69 | 72 | 73 |
74 | 75 | 76 | 77 |
80 | 81 |
82 |

Site built with pkgdown 2.0.1.

83 |
84 | 85 |
86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • essurvey 6 | 7 | 8 |
9 |
50 | 51 | 52 | 53 |
54 |
55 | 58 | 59 |
60 |

All vignettes

61 |

62 | 63 |
Introduction to the essurvey package
64 |
65 |
66 |
67 |
68 | 69 | 70 |
73 | 74 |
75 |

Site built with pkgdown 2.0.1.

76 |
77 | 78 |
79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • essurvey 6 | 7 | 8 |
9 |
50 | 51 | 52 | 53 |
54 |
55 |
56 | 59 | 60 | 61 |
  • 62 |

    Jorge Cimentada. Author, maintainer. 63 |

    64 |
  • 65 |
  • 66 |

    Thomas Leeper. Reviewer. 67 |
    Thomas reviewed the package for rOpensci,see https://github.com/ropensci/software-review/issues/201

    68 |
  • 69 |
  • 70 |

    Nujcharee Haswell. Reviewer. 71 |
    Nujcharee reviewed the package for rOpensci, see https://github.com/ropensci/software-review/issues/201

    72 |
  • 73 |
  • 74 |

    Jorge Lopez. Contributor. 75 |

    76 |
  • 77 |
  • 78 |

    François Briatte. Contributor. 79 |

    80 |
  • 81 |
82 |
83 |
84 |

Citation

85 | Source: inst/CITATION 86 |
87 |
88 | 89 | 90 |

Cimentada, Jorge (2019). Download Data from the European Social Survey on the Fly R package version 1.0.3

91 |
@Manual{,
 92 |   title = {Download Data from the European Social Survey on the Fly},
 93 |   author = {Jorge Cimentada},
 94 |   year = {2019},
 95 |   note = {R package version 1.0.3},
 96 |   url = {https://docs.ropensci.org/essurvey/},
 97 | }
98 | 99 |
100 | 101 |
102 | 103 | 104 | 105 |
108 | 109 |
110 |

Site built with pkgdown 2.0.1.

111 |
112 | 113 |
114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/cran-comments.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | cran-comments.md • ess 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 38 | 39 | 40 | 41 | 42 | 43 |
    44 |
    45 | 94 | 95 | 96 |
    97 | 98 |
    99 |
    100 | 103 | 104 | 105 |
    106 |

    107 | Test environments

    108 |
      109 |
    • local macOS High Sierra 10.13.3, R-3.4.3
    • 110 |
    • Ubuntu 14.04.5 LTS (on travis-ci), R-3.4.3
    • 111 |
    • win-builder
    • 112 |
    113 |
    114 |
    115 |

    116 | R CMD check results

    117 |

    0 errors | 0 warnings | 0 notes

    118 |

    For win-builder:

    119 |

    Status: 1 NOTE R Under development (unstable) (2018-02-19 r74276)

    120 |
    121 |
    122 |

    123 | Reverse dependencies

    124 |

    There are currently no downstream dependencies for this package.

    125 |
    126 |
      127 |
    • 128 | Most examples are wrapped in \dontrun{} because they cannot be run in < 5 seconds. No smaller toy examples can be created. Functions which can be executed in < 5 are allow to run.
    • 129 |
    130 |

    Also, most functions use personal emails to actually run. Even if using \dontshow{} I wouldn’t want to reveal any information (either on Github or somewhere on the CRAN repo) of personal use.

    131 |
      132 |
    • The tests are wrapped skip_on_cran() since they absolutely require using a private email. Full tests are run on Travis (weekly) with results available for review: https://travis-ci.org/cimentadaj/ess 133 |
    • 134 |
    135 |

    The Travis tests have an environment variable containing the email. This allows the tests to run smoothly.

    136 |
    137 | 138 | 139 |
    140 | 141 |
    142 | 143 | 144 |
    145 | 148 | 149 |
    150 |

    Site built with pkgdown.

    151 |
    152 | 153 |
    154 |
    155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/issue_template.html: -------------------------------------------------------------------------------- 1 | 2 | NA • essurvey 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 58 | 59 | 60 |
    61 |

    Expected Behavior

    62 | 63 | 64 |
    65 |
    66 |

    Current Behavior

    67 | 68 | 69 |
    70 |
    71 |

    Steps to Reproduce (for bugs)

    72 | 73 | 74 |
    1. 75 |
    2. 76 |
    3. 77 |
    4. 78 |
    79 |
    80 |

    Possible Solution

    81 | 82 | 83 |
    84 |
    85 |

    Context

    86 | 87 | 88 |
    89 |
    90 |

    Your Environment

    91 | 92 |
    93 | 94 | 95 |
    96 | 97 | 100 | 101 |
    102 | 103 | 104 | 105 |
    108 | 109 |
    110 |

    Site built with pkgdown 2.0.1.

    111 |
    112 | 113 |
    114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /docs/jquery.sticky-kit.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net 3 | */ 4 | (function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k)); 5 | if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("
    "))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q, 6 | u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}), 8 | a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize", 9 | y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/man/figures/ess_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/essurvey/b2d05a3a89120e15c0a0bea635ec1884adacb17d/docs/man/figures/ess_logo.png -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.16.2 2 | pkgdown: 2.0.1 3 | pkgdown_sha: ~ 4 | articles: 5 | intro_ess: intro_ess.html 6 | last_built: 2022-01-09T08:01Z 7 | 8 | -------------------------------------------------------------------------------- /docs/pull_request_template.html: -------------------------------------------------------------------------------- 1 | 2 | NA • essurvey 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 58 | 59 | 60 |
    61 |

    Description

    62 | 63 |
    64 |
    65 | 66 | 69 |
    70 |
    71 |

    Example

    72 | 74 |
    75 |
    76 |

    Best Practices

    77 | 79 |

    The following have been updated or added as needed: [ ] Documentation [ ] Examples in documentation [ ] Vignettes [ ] testthat Tests

    80 |
    81 | 82 | 83 |
    84 | 85 | 88 | 89 |
    90 | 91 | 92 | 93 |
    96 | 97 |
    98 |

    Site built with pkgdown 2.0.1.

    99 |
    100 | 101 |
    102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/essurvey/b2d05a3a89120e15c0a0bea635ec1884adacb17d/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/ess-package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ess: Download Data from the European Social Survey on the Fly — ess-package • ess 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 44 |
    45 |
    46 | 95 | 96 | 97 |
    98 | 99 |
    100 |
    101 | 105 | 106 | 107 |

    Download data from the European Social Survey directly from their website <http://www.europeansocialsurvey.org/>. There are two family of functions that allow you to download and interactively check all countries and rounds available.

    108 | 109 | 110 | 111 |

    Details

    112 | 113 |

    Note that this package is for downloading data from the ESS survey. 114 | For analyzing the data, the user should consider the weights and sampling 115 | design of each country/round combination as well as sampling between round. 116 | For some examples, check out the work of Anthony Damico and Daniel Oberski 117 | here. For detailed 118 | examples on how to explore/download data using package, visit the package website 119 | at https://cimentadaj.github.io/ess/

    120 | 121 |

    See also

    122 | 123 |

    Useful links:

    127 | 128 | 129 |
    130 | 145 |
    146 | 147 |
    148 | 151 | 152 |
    153 |

    Site built with pkgdown.

    154 |
    155 | 156 |
    157 |
    158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /docs/reference/figures/ess_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/essurvey/b2d05a3a89120e15c0a0bea635ec1884adacb17d/docs/reference/figures/ess_logo.png -------------------------------------------------------------------------------- /docs/reference/show_countries.html: -------------------------------------------------------------------------------- 1 | 2 | Return available countries in the European Social Survey — show_countries • essurvey 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    Return available countries in the European Social Survey

    63 |
    64 | 65 |
    66 |
    show_countries()
    67 |
    68 | 69 |
    70 |

    Value

    71 |

    character vector with available countries

    72 |
    73 | 74 |
    75 |

    Examples

    76 |
    
     77 | if (FALSE) {
     78 | show_countries()
     79 | }
     80 | 
     81 | 
     82 | 
    83 |
    84 |
    85 | 88 |
    89 | 90 | 91 |
    94 | 95 |
    96 |

    Site built with pkgdown 2.0.1.

    97 |
    98 | 99 |
    100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /docs/reference/show_rounds.html: -------------------------------------------------------------------------------- 1 | 2 | Return available rounds in the European Social Survey — show_rounds • essurvey 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    Return available rounds in the European Social Survey

    63 |
    64 | 65 |
    66 |
    show_rounds()
    67 |
    68 | 69 |
    70 |

    Value

    71 |

    numeric vector with available rounds

    72 |
    73 | 74 |
    75 |

    Examples

    76 |
    
     77 | if (FALSE) {
     78 | show_rounds()
     79 | }
     80 | 
     81 | 
     82 | 
    83 |
    84 |
    85 | 88 |
    89 | 90 | 91 |
    94 | 95 |
    96 |

    Site built with pkgdown 2.0.1.

    97 |
    98 | 99 |
    100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /404.html 5 | 6 | 7 | /CONDUCT.html 8 | 9 | 10 | /CONTRIBUTING.html 11 | 12 | 13 | /LICENSE-text.html 14 | 15 | 16 | /LICENSE.html 17 | 18 | 19 | /NEWS.html 20 | 21 | 22 | /articles/index.html 23 | 24 | 25 | /articles/intro_ess.html 26 | 27 | 28 | /authors.html 29 | 30 | 31 | /cran-comments.html 32 | 33 | 34 | /index.html 35 | 36 | 37 | /issue_template.html 38 | 39 | 40 | /news/index.html 41 | 42 | 43 | /pull_request_template.html 44 | 45 | 46 | /reference/ess-package.html 47 | 48 | 49 | /reference/ess_all_cntrounds.html 50 | 51 | 52 | /reference/ess_all_rounds.html 53 | 54 | 55 | /reference/ess_country.html 56 | 57 | 58 | /reference/ess_rounds.html 59 | 60 | 61 | /reference/essurvey-package.html 62 | 63 | 64 | /reference/import_country.html 65 | 66 | 67 | /reference/import_rounds.html 68 | 69 | 70 | /reference/import_sddf_country.html 71 | 72 | 73 | /reference/index.html 74 | 75 | 76 | /reference/recode_missings.html 77 | 78 | 79 | /reference/set_email.html 80 | 81 | 82 | /reference/show_countries.html 83 | 84 | 85 | /reference/show_country_rounds.html 86 | 87 | 88 | /reference/show_rounds.html 89 | 90 | 91 | /reference/show_rounds_country.html 92 | 93 | 94 | /reference/show_sddf_cntrounds.html 95 | 96 | 97 | /reference/show_theme_rounds.html 98 | 99 | 100 | /reference/show_themes.html 101 | 102 | 103 | -------------------------------------------------------------------------------- /essurvey.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader('To cite essurvey in publications use:') 2 | 3 | citEntry( 4 | entry = 'Manual', 5 | title = 'Download Data from the European Social Survey on the Fly', 6 | author = 'Jorge Cimentada ', 7 | year = '2019', 8 | note = 'R package version 1.0.3', 9 | url = 'https://docs.ropensci.org/essurvey/', 10 | textVersion = 'Cimentada, Jorge (2019). Download Data from the European Social Survey on the Fly R package version 1.0.3' 11 | ) 12 | -------------------------------------------------------------------------------- /man/essurvey-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/essurvey-package.R 3 | \docType{package} 4 | \name{essurvey-package} 5 | \alias{essurvey} 6 | \alias{essurvey-package} 7 | \title{essurvey: Download Data from the European Social Survey on the Fly} 8 | \description{ 9 | Download data from the European Social Survey directly from their website . There are two families of functions that allow you to download and interactively check all countries and rounds available. 10 | } 11 | \details{ 12 | Note that this package is for downloading data from the ESS survey. 13 | For analyzing the data, the user should consider the weights and sampling 14 | design of each country/round combination as well as sampling between rounds. 15 | For some examples, check out the work of Anthony Damico and Daniel Oberski 16 | \href{http://asdfree.com/european-social-survey-ess.html}{here}. For detailed 17 | examples on how to explore/download data using this package, visit the package website 18 | at \url{https://docs.ropensci.org/essurvey/} 19 | } 20 | \seealso{ 21 | Useful links: 22 | \itemize{ 23 | \item \url{https://docs.ropensci.org/essurvey/} 24 | \item \url{https://github.com/ropensci/essurvey} 25 | \item Report bugs at \url{https://github.com/ropensci/essurvey/issues} 26 | } 27 | 28 | } 29 | \author{ 30 | \strong{Maintainer}: Jorge Cimentada \email{cimentadaj@gmail.com} 31 | 32 | Other contributors: 33 | \itemize{ 34 | \item Thomas Leeper (Thomas reviewed the package for rOpensci,see https://github.com/ropensci/software-review/issues/201) [reviewer] 35 | \item Nujcharee Haswell (Nujcharee reviewed the package for rOpensci, see https://github.com/ropensci/software-review/issues/201) [reviewer] 36 | \item Jorge Lopez \email{jorge@loperez.com} [contributor] 37 | \item François Briatte \email{f.briatte@gmail.com} [contributor] 38 | } 39 | 40 | } 41 | \keyword{internal} 42 | -------------------------------------------------------------------------------- /man/figures/ess_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/essurvey/b2d05a3a89120e15c0a0bea635ec1884adacb17d/man/figures/ess_logo.png -------------------------------------------------------------------------------- /man/import_country.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/import_countries.R 3 | \name{import_country} 4 | \alias{import_country} 5 | \alias{import_all_cntrounds} 6 | \alias{download_country} 7 | \title{Download integrated rounds separately for countries from the European Social 8 | Survey} 9 | \usage{ 10 | import_country(country, rounds, ess_email = NULL, format = NULL) 11 | 12 | import_all_cntrounds(country, ess_email = NULL, format = NULL) 13 | 14 | download_country( 15 | country, 16 | rounds, 17 | ess_email = NULL, 18 | output_dir = getwd(), 19 | format = "stata" 20 | ) 21 | } 22 | \arguments{ 23 | \item{country}{a character of length 1 with the full name of the country. 24 | Use \code{\link{show_countries}} for a list of available countries.} 25 | 26 | \item{rounds}{a numeric vector with the rounds to download. See \code{\link{show_rounds}} 27 | for all available rounds.} 28 | 29 | \item{ess_email}{a character vector with your email, such as "your_email@email.com". 30 | If you haven't registered in the ESS website, create an account at 31 | \url{http://www.europeansocialsurvey.org/user/new}. A preferred method is to login 32 | through \code{\link{set_email}}.} 33 | 34 | \item{format}{the format from which to download the data. By default it is NULL for \code{import_*} functions and tries to read 'stata', 'spss' and 'sas' in the specific order. This can be useful if some countries don't have a particular format available. Alternatively, the user can specify the format which can either be 'stata', 'spss' or 'sas'. For the \code{download_*} functions it is set to 'stata' because the format should be specified before the downloading. When using \code{import_country} the data will be downloaded and read in the \code{format} specified. For \code{download_country}, the data is downloaded from the specified \code{format} (only 'spss' and 'stata' supported, see details).} 35 | 36 | \item{output_dir}{a character vector with the output directory in case you want to 37 | only download the files using \code{download_country}. Defaults to your working 38 | directory. This will be interpreted as a \strong{directory} and not a path with 39 | a file name.} 40 | } 41 | \value{ 42 | for \code{import_country} if \code{length(rounds)} is 1, it returns a tibble 43 | with the latest version of that round. Otherwise it returns a list of \code{length(rounds)} 44 | containing the latest version of each round. For \code{download_country}, if 45 | \code{output_dir} is a valid directory, it returns the saved directories invisibly 46 | and saves all the rounds in the chosen \code{format} in \code{output_dir} 47 | } 48 | \description{ 49 | Download integrated rounds separately for countries from the European Social 50 | Survey 51 | } 52 | \details{ 53 | Use \code{import_country} to download specified rounds for a given country and 54 | import them to R. 55 | \code{import_all_cntrounds} will download all rounds for a given country by default 56 | and \code{download_country} will download rounds and save them in a specified 57 | \code{format} in the supplied directory. 58 | 59 | The \code{format} argument from \code{import_country} should not matter to the user 60 | because the data is read into R either way. However, different formats might have 61 | different handling of the encoding of some questions. This option was preserved 62 | so that the user 63 | can switch between formats if any encoding errors are found in the data. For more 64 | details see the discussion \href{https://github.com/ropensci/essurvey/issues/11}{here}. 65 | For this particular argument, 'sas' is not supported because the data formats have 66 | changed between ESS waves and separate formats require different functions to be 67 | read. To preserve parsimony and format errors between waves, the user should use 68 | 'spss' or 'stata'. 69 | } 70 | \examples{ 71 | \dontrun{ 72 | 73 | set_email("your_email@email.com") 74 | 75 | # Get first three rounds for Denmark 76 | dk_three <- import_country("Denmark", 1:3) 77 | 78 | # Only download the files, this will return nothing 79 | 80 | temp_dir <- tempdir() 81 | 82 | download_country( 83 | "Turkey", 84 | rounds = c(2, 4), 85 | output_dir = temp_dir 86 | ) 87 | 88 | # By default, download_country downloads 'stata' files but 89 | # you can also download 'spss' or 'sas' files. 90 | 91 | download_country( 92 | "Turkey", 93 | rounds = c(2, 4), 94 | output_dir = temp_dir, 95 | format = 'spss' 96 | ) 97 | 98 | # If email is not registered at ESS website, error will arise 99 | uk_one <- import_country("United Kingdom", 5, "wrong_email@email.com") 100 | # Error in authenticate(ess_email) : 101 | # The email address you provided is not associated with any registered user. 102 | # Create an account at http://www.europeansocialsurvey.org/user/new 103 | 104 | # If selected rounds don't exist, error will arise 105 | 106 | czech_two <- import_country("Czech Republic", c(1, 22)) 107 | 108 | # Error in country_url(country, rounds) : 109 | # Only rounds ESS1, ESS2, ESS4, ESS5, ESS6, ESS7, ESS8 available 110 | # for Czech Republic 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /man/import_rounds.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/import_rounds.R 3 | \name{import_rounds} 4 | \alias{import_rounds} 5 | \alias{import_all_rounds} 6 | \alias{download_rounds} 7 | \title{Download integrated rounds from the European Social Survey} 8 | \usage{ 9 | import_rounds(rounds, ess_email = NULL, format = NULL) 10 | 11 | import_all_rounds(ess_email = NULL, format = NULL) 12 | 13 | download_rounds( 14 | rounds, 15 | ess_email = NULL, 16 | output_dir = getwd(), 17 | format = "stata" 18 | ) 19 | } 20 | \arguments{ 21 | \item{rounds}{a numeric vector with the rounds to download. See \code{\link{show_rounds}} 22 | for all available rounds.} 23 | 24 | \item{ess_email}{a character vector with your email, such as "your_email@email.com". 25 | If you haven't registered in the ESS website, create an account at 26 | \url{http://www.europeansocialsurvey.org/user/new}. A preferred method is to login 27 | through \code{\link{set_email}}.} 28 | 29 | \item{format}{the format from which to download the data. By default it is NULL for \code{import_*} functions and tries to read 'stata', 'spss' and 'sas' in the specific order. This can be useful if some countries don't have a particular format available. Alternatively, the user can specify the format which can either be 'stata', 'spss' or 'sas'. For the \code{download_*} functions it is set to 'stata' because the format should be specified before downloading. When using \code{import_country} the data will be downloaded and read in the \code{format} specified. For \code{download_country}, the data is downloaded from the specified \code{format} (only 'spss' and 'stata' supported, see details).} 30 | 31 | \item{output_dir}{a character vector with the output directory in case you want to only download the files using 32 | the \code{download_rounds}. Defaults to your working directory. This will be interpreted as 33 | a \strong{directory} and not a path with a file name.} 34 | } 35 | \value{ 36 | for \code{import_rounds} if \code{length(rounds)} is 1, it returns a tibble 37 | with the latest version of that round. Otherwise it returns a list of \code{length(rounds)} 38 | containing the latest version of each round. For \code{download_rounds}, if 39 | \code{output_dir} is a valid directory, it returns the saved directories invisibly 40 | and saves all the rounds in the chosen \code{format} in \code{output_dir} 41 | } 42 | \description{ 43 | Download integrated rounds from the European Social Survey 44 | } 45 | \details{ 46 | Use \code{import_rounds} to download specified rounds and import them to R. 47 | \code{import_all_rounds} will download all rounds by default and \code{download_rounds} 48 | will download rounds and save them in a specified \code{format} in the supplied 49 | directory. 50 | 51 | The \code{format} argument from \code{import_rounds} should not matter to the user 52 | because the data is read into R either way. However, different formats might have 53 | different handling of the encoding of some questions. This option was preserved 54 | so that the user 55 | can switch between formats if any encoding errors are found in the data. For more 56 | details see the discussion \href{https://github.com/ropensci/essurvey/issues/11}{here}. 57 | For this particular argument in, 'sas' is not supported because the data formats have 58 | changed between ESS waves and separate formats require different functions to be 59 | read. To preserve parsimony and format errors between waves, the user should use 60 | 'spss' or 'stata'. 61 | } 62 | \examples{ 63 | 64 | \dontrun{ 65 | 66 | set_email("your_email@email.com") 67 | 68 | # Get first three rounds 69 | three_rounds <- import_rounds(1:3) 70 | 71 | temp_dir <- tempdir() 72 | 73 | # Only download the files to output_dir, this will return nothing. 74 | download_rounds( 75 | rounds = 1:3, 76 | output_dir = temp_dir, 77 | ) 78 | 79 | # By default, download_rounds saves a 'stata' file. You can 80 | # also download 'spss' and 'sas' files. 81 | 82 | download_rounds( 83 | rounds = 1:3, 84 | output_dir = temp_dir, 85 | format = 'spss' 86 | ) 87 | 88 | # If rounds are repeated, will download only unique ones 89 | two_rounds <- import_rounds(c(1, 1)) 90 | 91 | # If email is not registered at ESS website, error will arise 92 | two_rounds <- import_rounds(c(1, 2), "wrong_email@email.com") 93 | 94 | # Error in authenticate(ess_email) : 95 | # The email address you provided is not associated with any registered user. 96 | # Create an account at https://www.europeansocialsurvey.org/user/new 97 | 98 | # If selected rounds don't exist, error will arise 99 | 100 | two_rounds <- import_rounds(c(1, 22)) 101 | # Error in round_url(rounds) : 102 | # ESS round 22 is not a available. Check show_rounds() 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /man/import_sddf_country.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/import_sddf_country.R 3 | \name{import_sddf_country} 4 | \alias{import_sddf_country} 5 | \alias{import_all_sddf_cntrounds} 6 | \alias{download_sddf_country} 7 | \title{Download SDDF data by round for countries from the European Social Survey} 8 | \usage{ 9 | import_sddf_country(country, rounds, ess_email = NULL, format = NULL) 10 | 11 | import_all_sddf_cntrounds(country, ess_email = NULL, format = NULL) 12 | 13 | download_sddf_country( 14 | country, 15 | rounds, 16 | ess_email = NULL, 17 | output_dir = getwd(), 18 | format = "stata" 19 | ) 20 | } 21 | \arguments{ 22 | \item{country}{a character of length 1 with the full name of the country. 23 | Use \code{\link{show_countries}} for a list of available countries.} 24 | 25 | \item{rounds}{a numeric vector with the rounds to download. See \code{\link{show_sddf_cntrounds}} 26 | for all available rounds for any given country.} 27 | 28 | \item{ess_email}{a character vector with your email, such as "your_email@email.com". 29 | If you haven't registered in the ESS website, create an account at 30 | \url{http://www.europeansocialsurvey.org/user/new}. A preferred method is to login 31 | through \code{\link{set_email}}.} 32 | 33 | \item{format}{the format from which to download the data. By default it is NULL for \code{import_*} functions and tries to read 'stata', 'spss' and 'sas' in the specific order. This can be useful if some countries don't have a particular format available. Alternatively, the user can specify the format which can either be 'stata', 'spss' or 'sas'. 34 | For the \code{download_*} functions it is set to 'stata' because the format should be 35 | specified before downloading. Setting it to \code{NULL} will iterate over 'stata', 36 | 'spss' and 'sas' and download the first that is available. When using \code{import_country} 37 | the data will be downloaded and read in the \code{format} specified. For \code{download_country}, 38 | the data is downloaded from the specified \code{format} (only 'spss' and 'stata' supported, 39 | see details).} 40 | 41 | \item{output_dir}{a character vector with the output directory in case you want to 42 | only download the files using \code{download_sddf_country}. Defaults to your working 43 | directory. This will be interpreted as a \strong{directory} and not a path with 44 | a file name.} 45 | } 46 | \value{ 47 | for \code{import_sddf_country} if \code{length(rounds)} is 1, it returns a tibble with 48 | the latest version of that round. Otherwise it returns a list of \code{length(rounds)} 49 | containing the latest version of each round. For \code{download_sddf_country}, if 50 | \code{output_dir} is a valid directory, it returns the saved directories invisibly and saves 51 | all the rounds in the chosen \code{format} in \code{output_dir} 52 | } 53 | \description{ 54 | Download SDDF data by round for countries from the European Social Survey 55 | } 56 | \details{ 57 | SDDF data (Sample Design Data Files) are data sets that contain additional columns with the 58 | sample design and weights for a given country in a given round. These additional columns are 59 | required to perform any complex weighted analysis of the ESS data. Users interested in using this data 60 | should read the description of SDDF files \href{http://www.europeansocialsurvey.org/methodology/ess_methodology/sampling.html}{here} 61 | and should read \href{http://www.europeansocialsurvey.org/data/download_sample_data.html}{here} for the 62 | sampling design of the country of analysis for that specific round. 63 | 64 | Use \code{import_sddf_country} to download the SDDF data by country into R. 65 | \code{import_all_sddf_cntrounds} will download all available SDDF data for a given country by 66 | default and \code{download_sddf_country} will download SDDF data and save them in a specified 67 | \code{format} in the supplied directory. 68 | 69 | The \code{format} argument from \code{import_country} should not matter to the user 70 | because the data is read into R either way. However, different formats might have 71 | different handling of the encoding of some questions. This option was preserved 72 | so that the user can switch between formats if any encoding errors are found in the data. For more 73 | details see the discussion \href{https://github.com/ropensci/essurvey/issues/11}{here}. 74 | 75 | Additionally, given that the SDDF data is not very complete, some countries do not have SDDF data 76 | in Stata or SPSS formats. For that reason, the \code{format} argument is not used in \code{import_sddf_country}. 77 | Internally, \code{Stata} is chosen over \code{SPSS} and \code{SPSS} over \code{SAS} in that 78 | order of preference. 79 | 80 | For this particular argument, 'sas' is not supported because the data formats have 81 | changed between ESS waves and separate formats require different functions to be 82 | read. To preserve parsimony and format errors between waves, the user should use 83 | 'stata' or 'spss'. 84 | 85 | Starting from round 7 (including), the ESS switched the layout of SDDF data. 86 | Before the rounds, SDDF data was published separately by wave-country 87 | combination. From round 7 onwards, all SDDF data is released as a single 88 | integrated file with all countries combined for that given round. \code{import_sddf_country} 89 | takes care of this nuance by reading the data and filtering the chosen 90 | country automatically. \code{download_sddf_country} downloads the raw file but also 91 | reads the data into memory to subset the specific country requested. This 92 | process should be transparent to the user but beware that reading/writing the data might delete 93 | some of it's properties such as dropping the labels or label attribute. 94 | } 95 | \examples{ 96 | \dontrun{ 97 | 98 | set_email("your_email@email.com") 99 | 100 | sp_three <- import_sddf_country("Spain", 5:6) 101 | 102 | show_sddf_cntrounds("Spain") 103 | 104 | # Only download the files, this will return nothing 105 | 106 | temp_dir <- tempdir() 107 | 108 | download_sddf_country( 109 | "Spain", 110 | rounds = 5:6, 111 | output_dir = temp_dir 112 | ) 113 | 114 | # By default, download_sddf_country downloads 'stata' files but 115 | # you can also download 'spss' or 'sas' files. 116 | 117 | download_sddf_country( 118 | "Spain", 119 | rounds = 1:8, 120 | output_dir = temp_dir, 121 | format = 'spss' 122 | ) 123 | 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /man/recode_missings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/recode_missings.R 3 | \name{recode_missings} 4 | \alias{recode_missings} 5 | \alias{recode_numeric_missing} 6 | \alias{recode_strings_missing} 7 | \title{Recode pre-defined missing values as NA} 8 | \usage{ 9 | recode_missings(ess_data, missing_codes) 10 | 11 | recode_numeric_missing(x, missing_codes) 12 | 13 | recode_strings_missing(y, missing_codes) 14 | } 15 | \arguments{ 16 | \item{ess_data}{data frame or \code{\link[tibble]{tibble}} with data from the 17 | European Social Survey. This data frame should come either 18 | from \code{\link{import_rounds}}, \code{\link{import_country}} or read with 19 | \code{\link[haven]{read_dta}} or \code{\link[haven]{read_spss}}. This is the case because it 20 | identifies missing values using \code{\link[haven]{labelled}} classes.} 21 | 22 | \item{missing_codes}{a character vector with values 'Not applicable', 23 | 'Refusal', 'Don't Know', 'No answer' or 'Not available'. By default 24 | all values are chosen. Note that the wording is case sensitive.} 25 | 26 | \item{x}{a \code{\link[haven]{labelled}} numeric} 27 | 28 | \item{y}{a character vector} 29 | } 30 | \value{ 31 | The same data frame or \code{\link[tibble]{tibble}} but with values 'Not applicable', 32 | 'Refusal', 'Don't Know', 'No answer' and 'Not available' recoded 33 | as NA. 34 | } 35 | \description{ 36 | This function is not needed any more, please see the details section. 37 | } 38 | \details{ 39 | Data from the European Social Survey is always accompanied by a script 40 | that recodes the categories 'Not applicable', 'Refusal', 'Don't Know', 41 | 'No answer' and 'Not available' to missing. This function recodes 42 | these categories to NA 43 | 44 | 45 | 46 | The European Social Survey now provides these values recoded automatically 47 | in Stata data files. These missing categories are now read as missing values 48 | by \code{\link[haven]{read_dta}}, reading the missing categories correctly from Stata.For an example on how these values are coded, see \href{https://github.com/ropensci/essurvey/issues/35}{here}. 49 | 50 | Old details: 51 | 52 | When downloading data directly from the European Social Survey's website, 53 | the downloaded .zip file contains a script that recodes some categories 54 | as missings in Stata and SPSS formats. 55 | 56 | For recoding numeric variables \code{recode_numeric_missings} 57 | uses the labels provided by the \code{\link[haven]{labelled}} 58 | class to delete the labels matched in \code{missing_codes}. For the 59 | character variables matching is done with the underlying number assigned to 60 | each category, namely 6, 7, 8, 9 and 9 for 'Not applicable', Refusal', 61 | 'Don't Know', No answer' and 'Not available'. 62 | 63 | The functions are a direct translation of the Stata script that comes 64 | along when downloading one of the rounds. The Stata script is the same 65 | for all rounds and all countries, meaning that these functions work 66 | for all rounds. 67 | } 68 | \examples{ 69 | \dontrun{ 70 | seven <- import_rounds(7, your_email) 71 | 72 | attr(seven$tvtot, "labels") 73 | mean(seven$tvtot, na.rm = TRUE) 74 | 75 | names(table(seven$lnghom1)) 76 | # First three are actually missing values 77 | 78 | seven_recoded <- recode_missings(seven) 79 | 80 | attr(seven_recoded$tvtot, "labels") 81 | # All missings have been removed 82 | mean(seven_recoded$tvtot, na.rm = TRUE) 83 | 84 | names(table(seven_recoded$lnghom1)) 85 | # All missings have been removed 86 | 87 | # If you want to operate on specific variables 88 | # you can use other recode_*_missing 89 | 90 | seven$tvtot <- recode_numeric_missing(seven$tvtot) 91 | 92 | # Recode only 'Don't know' and 'No answer' to missing 93 | seven$tvpol <- recode_numeric_missing(seven$tvpol, c("Don't know", "No answer")) 94 | 95 | 96 | # The same can be done with recode_strings_missing 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /man/set_email.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/set_email.R 3 | \name{set_email} 4 | \alias{set_email} 5 | \title{Save your ESS email as an environment variable} 6 | \usage{ 7 | set_email(ess_email) 8 | } 9 | \arguments{ 10 | \item{ess_email}{a character string with your registered email.} 11 | } 12 | \description{ 13 | Save your ESS email as an environment variable 14 | } 15 | \details{ 16 | You should only run \code{set_email()} once and every \code{import_} and \code{download_} function 17 | should work fine. Make sure your email is registered at 18 | \url{http://www.europeansocialsurvey.org/} before setting the email. 19 | } 20 | \examples{ 21 | 22 | \dontrun{ 23 | set_email("my_registered@email.com") 24 | 25 | import_rounds(1) 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /man/show_countries.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/show_funs.R 3 | \name{show_countries} 4 | \alias{show_countries} 5 | \title{Return available countries in the European Social Survey} 6 | \usage{ 7 | show_countries() 8 | } 9 | \value{ 10 | character vector with available countries 11 | } 12 | \description{ 13 | Return available countries in the European Social Survey 14 | } 15 | \examples{ 16 | 17 | \dontrun{ 18 | show_countries() 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /man/show_country_rounds.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/show_any_rounds.R 3 | \name{show_country_rounds} 4 | \alias{show_country_rounds} 5 | \title{Return available rounds for a country in the European Social Survey} 6 | \usage{ 7 | show_country_rounds(country) 8 | } 9 | \arguments{ 10 | \item{country}{A character of length 1 with the full name of the country. 11 | Use \code{\link{show_countries}}for a list of available countries.} 12 | } 13 | \value{ 14 | numeric vector with available rounds for \code{country} 15 | } 16 | \description{ 17 | Return available rounds for a country in the European Social Survey 18 | } 19 | \examples{ 20 | 21 | \dontrun{ 22 | 23 | show_country_rounds("Spain") 24 | 25 | show_country_rounds("Turkey") 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/show_rounds.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/show_funs.R 3 | \name{show_rounds} 4 | \alias{show_rounds} 5 | \title{Return available rounds in the European Social Survey} 6 | \usage{ 7 | show_rounds() 8 | } 9 | \value{ 10 | numeric vector with available rounds 11 | } 12 | \description{ 13 | Return available rounds in the European Social Survey 14 | } 15 | \examples{ 16 | 17 | \dontrun{ 18 | show_rounds() 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /man/show_rounds_country.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/show_any_rounds.R 3 | \name{show_rounds_country} 4 | \alias{show_rounds_country} 5 | \title{Return countries that participated in \strong{all} of the specified rounds.} 6 | \usage{ 7 | show_rounds_country(rounds, participate = TRUE) 8 | } 9 | \arguments{ 10 | \item{rounds}{A numeric vector specifying the rounds from which to return the countries. 11 | Use \code{\link{show_rounds}}for a list of available rounds.} 12 | 13 | \item{participate}{A logical that controls whether to show participating countries in that/those 14 | rounds or countries that didn't participate. Set to \code{TRUE} by default.} 15 | } 16 | \value{ 17 | A character vector with the country names 18 | } 19 | \description{ 20 | Return countries that participated in \strong{all} of the specified rounds. 21 | } 22 | \details{ 23 | \code{show_rounds_country} returns the countries that participated in 24 | \strong{all} of the specified rounds. That is, \code{show_rounds_country(1:2)} 25 | will return countries that participated both in round 1 and round 2. Conversely, 26 | if \code{participate = FALSE} it will return the countries that did not 27 | participate in \strong{both} round 1 and round 2. 28 | } 29 | \examples{ 30 | 31 | \dontrun{ 32 | 33 | # Return countries that participated in round 2 34 | 35 | show_rounds_country(2) 36 | 37 | # Return countries that participated in all rounds 38 | 39 | show_rounds_country(1:8) 40 | 41 | # Return countries that didn't participate in the first three rounds 42 | 43 | show_rounds_country(1:3, participate = FALSE) 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /man/show_sddf_cntrounds.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/show_sddf_cntrounds.R 3 | \name{show_sddf_cntrounds} 4 | \alias{show_sddf_cntrounds} 5 | \title{Return available SDDF rounds for a country in the European Social Survey} 6 | \usage{ 7 | show_sddf_cntrounds(country, ess_email = NULL) 8 | } 9 | \arguments{ 10 | \item{country}{A character of length 1 with the full name of the country. 11 | Use \code{\link{show_countries}} for a list of available countries.} 12 | 13 | \item{ess_email}{a character vector with your email, such as "your_email@email.com". 14 | If you haven't registered in the ESS website, create an account at 15 | \url{http://www.europeansocialsurvey.org/user/new}. A preferred method is to login 16 | through \code{\link{set_email}}.} 17 | } 18 | \value{ 19 | numeric vector with available rounds for \code{country} 20 | } 21 | \description{ 22 | Return available SDDF rounds for a country in the European Social Survey 23 | } 24 | \details{ 25 | SDDF data are the equivalent weight data used to analyze the European Social Survey 26 | properly. For more information, see the details section of \code{\link{import_sddf_country}}. 27 | As an exception to the \code{show_*} family of functions, \code{show_sddf rounds} 28 | needs your ESS email to check which rounds are available. Be sure to add it 29 | with \code{\link{set_email}}. 30 | } 31 | \examples{ 32 | 33 | \dontrun{ 34 | set_email("your_email@email.com") 35 | 36 | show_sddf_cntrounds("Spain") 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /man/show_theme_rounds.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/show_any_rounds.R 3 | \name{show_theme_rounds} 4 | \alias{show_theme_rounds} 5 | \title{Return available rounds for a theme in the European Social Survey} 6 | \usage{ 7 | show_theme_rounds(theme) 8 | } 9 | \arguments{ 10 | \item{theme}{A character of length 1 with the full name of the theme. 11 | Use \code{\link{show_themes}}for a list of available themes.} 12 | } 13 | \value{ 14 | numeric vector with available rounds for \code{country} 15 | } 16 | \description{ 17 | This function returns the available rounds for any theme from 18 | \code{\link{show_themes}}. However, contrary to \code{\link{show_country_rounds}} 19 | themes can not be downloaded as separate datasets. This and the 20 | \code{\link{show_themes}} function serve purely for informative purposes. 21 | } 22 | \examples{ 23 | 24 | \dontrun{ 25 | chosen_theme <- show_themes()[3] 26 | 27 | # In which rounds was the topic of 'Democracy' asked? 28 | show_theme_rounds(chosen_theme) 29 | 30 | # And politics? 31 | show_theme_rounds("Politics") 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /man/show_themes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/show_funs.R 3 | \name{show_themes} 4 | \alias{show_themes} 5 | \title{Return available themes in the European Social Survey} 6 | \usage{ 7 | show_themes() 8 | } 9 | \value{ 10 | character vector with available themes 11 | } 12 | \description{ 13 | This function returns the available themes in the European Social Survey. 14 | However, contrary to \code{\link{show_countries}} and \code{\link{show_country_rounds}}, 15 | themes can not be downloaded as separate datasets. This and 16 | \code{\link{show_theme_rounds}} serve purely for informative purposes. 17 | } 18 | \examples{ 19 | 20 | \dontrun{ 21 | show_themes() 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /revdep/check.R: -------------------------------------------------------------------------------- 1 | library("devtools") 2 | 3 | revdep_check() 4 | revdep_check_save_summary() 5 | revdep_check_print_problems() 6 | -------------------------------------------------------------------------------- /revdep/checks.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ropensci/essurvey/b2d05a3a89120e15c0a0bea635ec1884adacb17d/revdep/checks.rds -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(essurvey) 3 | 4 | test_check("essurvey") -------------------------------------------------------------------------------- /tests/testthat/test-3-rounds.R: -------------------------------------------------------------------------------- 1 | 2 | run_long_tests <- identical("true", Sys.getenv("NOT_CRAN")) 3 | 4 | if (run_long_tests) { 5 | # Environment variables from GH actions 6 | ess_email <- Sys.getenv("ESS_EMAIL") 7 | round_one <- import_rounds(1, ess_email) 8 | 9 | # Test for all rounds 10 | available_rounds <- show_rounds() 11 | all_rounds <- import_rounds(available_rounds, ess_email) 12 | } 13 | 14 | test_that("import_rounds checks for args", { 15 | skip_on_cran() 16 | expect_error(import_rounds(numeric()), 17 | regexp = "length(rounds) > 0", 18 | fixed = TRUE) 19 | }) 20 | 21 | test_that("download_rounds checks for args", { 22 | skip_on_cran() 23 | expect_error(download_rounds(numeric()), 24 | regexp = "length(rounds) > 0", 25 | fixed = TRUE) 26 | }) 27 | 28 | 29 | test_that("import_round for only one round", { 30 | 31 | skip_on_cran() 32 | 33 | # check is list 34 | expect_is(round_one, "data.frame") 35 | 36 | # check it is the first round 37 | expect_true(unique(round_one$essround) == 1) 38 | 39 | # check that the number of rows is greater than 0 40 | expect_gt(nrow(round_one), 0) 41 | 42 | # check that the number of columns is greater than 0 43 | expect_gt(ncol(round_one), 0) 44 | }) 45 | 46 | test_that("import_round for all rounds", { 47 | 48 | skip_on_cran() 49 | 50 | # check is list 51 | expect_is(all_rounds, "list") 52 | 53 | # check is length seven 54 | expect_length(all_rounds, length(available_rounds)) 55 | 56 | # check that all ess returns data frames 57 | expect_true(all(vapply(all_rounds, 58 | function(x) "data.frame" %in% class(x), 59 | FUN.VALUE = logical(1)))) 60 | 61 | # Check that all rounds are indeed the first seven rounds 62 | expect_true(all(vapply(all_rounds, 63 | function(x) unique(x$essround), 64 | FUN.VALUE = numeric(1)) == available_rounds)) 65 | 66 | # check that all data frames have more than 0 rows 67 | expect_equal(all(vapply(all_rounds, nrow, numeric(1)) > 0), TRUE) 68 | 69 | # check that all data frames have more than 0 columns 70 | expect_equal(all(vapply(all_rounds, ncol, numeric(1)) > 0), TRUE) 71 | }) 72 | 73 | test_that("download_round for downloading works fine", { 74 | 75 | skip_on_cran() 76 | # Test whether you get a message where the downloads are at 77 | expect_message(downloads <- 78 | download_rounds( 79 | 1, 80 | ess_email, 81 | output_dir = tempdir(), 82 | format = "stata"), 83 | "All files saved to") 84 | 85 | # Test whether the downloaded files are indeed there 86 | ess_files <- list.files(downloads, pattern = "ESS", recursive = TRUE) 87 | 88 | # Same number of stata files as the rounds attempted 89 | # to download? 90 | expect_equal(sum(grepl(".dta", ess_files)), 1) 91 | 92 | # Same number of zip files as the rounds attempted 93 | # to download? 94 | expect_equal(sum(grepl(".zip", ess_files)), 1) 95 | 96 | # Same number of do files as the rounds attempted 97 | # to download? 98 | expect_equal(sum(grepl(".do", ess_files)), 1) 99 | 100 | # Delete all downloaded files 101 | unlink(downloads, recursive = TRUE, force = TRUE) 102 | }) 103 | 104 | test_that("output_dir should be valid", { 105 | 106 | skip_on_cran() 107 | 108 | # Here output_dir is set to NULL 109 | expect_error(download_rounds(1, 110 | ess_email, 111 | output_dir = NULL)) 112 | }) 113 | 114 | test_that("import_round files with other non-stata format", { 115 | skip_on_cran() 116 | 117 | # Test for only one wave 118 | wave_one <- import_rounds(1, ess_email, format = "spss") 119 | 120 | # check is list 121 | expect_is(wave_one, "data.frame") 122 | 123 | # check that the number of rows is greater than 0 124 | expect_gt(nrow(wave_one), 0) 125 | 126 | # check that the number of columns is greater than 0 127 | expect_gt(ncol(wave_one), 0) 128 | 129 | }) 130 | 131 | test_that("Specify 'sas' for import_rounds data throws error",{ 132 | skip_on_cran() 133 | 134 | expect_error(import_rounds(1, ess_email, format = "sas"), 135 | "You cannot read SAS but only 'spss' and 'stata' files with this function") # nolint 136 | }) 137 | 138 | -------------------------------------------------------------------------------- /tests/testthat/test-4-recode_missings.R: -------------------------------------------------------------------------------- 1 | context("test-recode_missings.R") 2 | 3 | run_long_tests <- identical("true", Sys.getenv("NOT_CRAN")) 4 | 5 | if (run_long_tests) { 6 | ess_email <- Sys.getenv("ESS_EMAIL") 7 | round_seven <- import_rounds(7, ess_email) 8 | } 9 | 10 | test_that("recoded object is a df", { 11 | skip_on_cran() 12 | 13 | recode_esp <- recode_missings(round_seven) 14 | expect_is(recode_esp, "data.frame") 15 | }) 16 | 17 | test_that("recode_missing correctly recodes chr na's", { 18 | skip_on_cran() 19 | 20 | recode_esp <- recode_missings(round_seven) 21 | 22 | chrs <- vapply(recode_esp, is.character, logical(1)) 23 | 24 | chr_miss <- vapply(recode_esp[chrs], function(.x) sum(is.na(.x)), numeric(1)) 25 | 26 | # These are the missing values taken from running this script 27 | # in stata. This is only for comparison. 28 | stata_chr_missings <- c(name = 0, 29 | edition = 0, 30 | proddate = 0, 31 | cntry = 0, 32 | ctzshipc = 38249, 33 | cntbrthc = 35876, 34 | lnghom1 = 310, 35 | lnghom2 = 2363, 36 | fbrncntb = 33534, 37 | mbrncntb = 33789, 38 | region = 3) 39 | 40 | expect_equal(chr_miss, stata_chr_missings) 41 | }) 42 | 43 | test_that("recoding_mising correctly recodes numeric na's", { 44 | skip_on_cran() 45 | 46 | recode_esp <- recode_missings(round_seven) 47 | num_miss <- vapply(recode_esp[c("tvtot", "agea", "vote")], 48 | function(x) sum(is.na(x)), numeric(1)) 49 | 50 | stata_num_missings <- c(tvtot = 74, 51 | agea = 99, 52 | vote = 328) 53 | 54 | expect_equal(num_miss, stata_num_missings) 55 | }) 56 | 57 | test_that("recoding_missing recodes cutomized labels", { 58 | skip_on_cran() 59 | 60 | recode_esp <- recode_missings(round_seven) 61 | 62 | remove_labels <- c("Don't know", "Not available") 63 | equivalent_codes <- c("888", "999") # for strings! 64 | 65 | custom_esp <- recode_missings(round_seven, remove_labels) 66 | 67 | # For numeric variables 68 | removed <- all(!remove_labels %in% names(attr(custom_esp$tvtot, "labels"))) 69 | expect_true(removed) 70 | 71 | # For character variables 72 | removed <- all(!equivalent_codes %in% names(table(custom_esp$lnghom1))) 73 | expect_true(removed) 74 | }) 75 | 76 | test_that("recode_numeric can recode customized labels", { 77 | all_codes <- .global_vars$all_codes 78 | 79 | skip_on_cran() 80 | 81 | removed_miss <- names(attr(recode_numeric_missing(round_seven$tvtot), "labels")) 82 | 83 | # All codes were removed 84 | expect_true(all(!all_codes %in% removed_miss)) 85 | 86 | act_labels <- attr(recode_numeric_missing(round_seven$tvtot, c("Don't know")), 87 | "labels") 88 | 89 | expect_true(!"Don't know" %in% names(act_labels)) 90 | 91 | expect_error( 92 | recode_numeric_missing(round_seven$tvtot, c("Hey", "Don't know")), 93 | "Codes not available: Hey" 94 | ) 95 | 96 | expect_error( 97 | recode_numeric_missing(round_seven$tvtot, c("Hey", "Another", "Don't know")), 98 | "Codes not available: Hey, Another" 99 | ) 100 | }) 101 | 102 | test_that("recode_strings can recode customized labels", { 103 | all_codes <- .global_vars$all_codes 104 | 105 | skip_on_cran() 106 | 107 | # 777, 888, 999 108 | removed_miss <- 109 | c("777", "888", "999") %in% 110 | names(table(recode_strings_missing(round_seven$lnghom1))) 111 | 112 | # All codes were removed 113 | expect_true(!all(removed_miss)) 114 | 115 | ### Remove 'Don't know: 888 116 | remove_dk <- recode_strings_missing(round_seven$lnghom1, "Don't know") 117 | removed_miss <- 118 | "888" %in% 119 | names(table(remove_dk)) 120 | 121 | expect_true(!all(removed_miss)) 122 | 123 | kept_miss <- 124 | c("777", "999") %in% 125 | names(table(remove_dk)) 126 | 127 | expect_true(all(kept_miss)) 128 | 129 | expect_error( 130 | recode_strings_missing(round_seven$lnghom1, c("Hey", "Don't know")), 131 | "Codes not available: Hey" 132 | ) 133 | 134 | expect_error( 135 | recode_strings_missing(round_seven$lnghom1, c("Hey", "Another", "Don't know")), 136 | "Codes not available: Hey, Another" 137 | ) 138 | }) 139 | -------------------------------------------------------------------------------- /tests/testthat/test-6-country_lookup.R: -------------------------------------------------------------------------------- 1 | test_that("Test that all current ESS countries have equivalent country lookups", { 2 | skip_on_cran() 3 | # To avoid any surprises, we always test that available ESS countries DON'T 4 | # have NA values in their 2 letter chr codes because that would introduce very 5 | # random errors. 6 | 7 | countries <- show_countries() 8 | res <- country_lookup[countries] 9 | 10 | expect_named(res) 11 | expect_true(all(!is.na(res))) 12 | expect_true(all(!is.na(names(res)))) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-7-set_email.R: -------------------------------------------------------------------------------- 1 | context("test-set_email") 2 | ess_email <- Sys.getenv("ESS_EMAIL") 3 | save_dir <- tempdir() 4 | 5 | # Test for set_email 6 | test_that("test email is correctly set and can be overwritten", { 7 | skip_on_cran() 8 | old_env_var <- Sys.getenv("ESS_EMAIL") 9 | 10 | set_email(ess_email = "test@test.com") 11 | expect_equal(Sys.getenv("ESS_EMAIL"), "test@test.com") 12 | set_email(ess_email = "test_bis@test.com") 13 | expect_equal(Sys.getenv("ESS_EMAIL"), "test_bis@test.com") 14 | 15 | # Reset 16 | Sys.setenv("ESS_EMAIL" = old_env_var) 17 | }) 18 | 19 | test_that("authenticate works correctly for wrong emails", { 20 | skip_on_cran() 21 | expect_error(authenticate("random@email.morerandom"), 22 | "email address you provided is not associated with any registered") # nolint 23 | 24 | expect_error(authenticate(""), 25 | "email address you provided is not associated with any registered") # nolint 26 | }) 27 | -------------------------------------------------------------------------------- /vignettes/precompile.R: -------------------------------------------------------------------------------- 1 | knitr::knit("./intro_ess.Rmd.orig", "./intro_ess.Rmd") 2 | --------------------------------------------------------------------------------