Skip to content

Commit

Permalink
add all questionnaires btwn 1960 and 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Jan 8, 2024
1 parent 4965463 commit bd899a9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
.RData
^_pkgdown\.yml$
^pkgdown$
^data_prep
^data_prep/
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
* Minor changes
* Replaced `.onAttach` by `.onLoad` so that the package works with `censobr::function()`
* Fixed documentation of various functions.
* Fixed issue to make sure censobr uses suggested packages conditionally on CRAN

* Data included in this version:
* New data set and files included in this version:
* 2022 census [*New*]
* Questionnaires and interview manuals
* Short questionnaires for every census between 1960 and 2022.
* Long questionnaire for the 1960 and 2022 censuses.


# censobr v0.2.0
Expand Down
11 changes: 6 additions & 5 deletions R/docs_questionnaire.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#' @template year
#' @param type Character. The type of questionnaire used in the survey, whether
#' the `"long"` one used in the sample component of the census, or the
#' `"short"` one, which is answered by more households. Options currently
#' include `c("long")`.
#' `"short"` one, which is answered by more households. Options include
#' `c("long", "short")`.
#' @template showProgress
#' @template cache
#'
Expand All @@ -25,21 +25,22 @@ questionnaire <- function(year = 2010,
type = NULL,
showProgress = TRUE,
cache = TRUE){
# year = 2010
# year = 2000
# type = 'short'
# type = 'long'

### check inputs
checkmate::assert_numeric(year)
checkmate::assert_string(type)

# data available for the years:
years <- c(1970, 1980, 1991, 2000, 2010, 2022)
years <- c(1960, 1970, 1980, 1991, 2000, 2010, 2022)
if (isFALSE(year %in% years)) { stop( paste0("Error: Questionnaire currently only available for the years: ",
paste(years), collapse = " ")
)}

# data available for data sets:
data_sets <- c('long')
data_sets <- c('long', 'short')
if (isFALSE(type %in% data_sets)) { stop( paste0("Error: Questionnaire currently only available for the types: ",
paste(data_sets, collapse = ", "))
)}
Expand Down
16 changes: 9 additions & 7 deletions tests/testthat/test_docs_questionnaire.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ testthat::skip_on_cran()
test_that("questionnaire", {

# download files
testthat::expect_message( questionnaire(year = 2022, type = 'long') )
testthat::expect_message( questionnaire(year = 2010, type = 'long') )
testthat::expect_message( questionnaire(year = 2000, type = 'long') )
testthat::expect_message( questionnaire(year = 1991, type = 'long') )
testthat::expect_message( questionnaire(year = 1980, type = 'long') )
testthat::expect_message( questionnaire(year = 1970, type = 'long') )
for (y in c(1960, 1970, 1980, 1991, 2000, 2010, 2022)) {

for (t in c('long', 'short')) {
testthat::expect_message(questionnaire(year = y, type = t))
}

}


# cache dir
pkgv <- paste0('censobr/data_release_', data_release)
cache_dir <- tools::R_user_dir(pkgv, which = 'cache')

## check if file have been downloaded
years <- c(1970, 1980, 1991, 2000, 2010, 2022)
years <- c(1960, 1970, 1980, 1991, 2000, 2010, 2022)

lapply(X=years, FUN = function(y){
f_address <- paste0(cache_dir,'/',y, '_questionnaire_long.pdf')
Expand Down

0 comments on commit bd899a9

Please sign in to comment.