diff --git a/DESCRIPTION b/DESCRIPTION index 4521ef5..2f90514 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: readabs Type: Package Title: Download and Tidy Time Series Data from the Australian Bureau of Statistics -Version: 0.4.20 +Version: 0.4.30 Authors@R: c( person("Matt", "Cowgill", role = c("aut", "cre"), email = "mattcowgill@gmail.com", comment = c(ORCID = "0000-0003-0422-3300")), person("Zoe", "Meers", role = "aut", email = "zoe.meers@sydney.edu.au"), @@ -35,7 +35,6 @@ Imports: labelled URL: https://github.com/mattcowgill/readabs BugReports: https://github.com/mattcowgill/readabs/issues -RoxygenNote: 7.3.2 VignetteBuilder: knitr Suggests: knitr, @@ -44,3 +43,4 @@ Suggests: testthat (>= 2.1.0), ggplot2 Roxygen: list(markdown = TRUE) +Config/roxygen2/version: 8.0.0 diff --git a/NEWS.md b/NEWS.md index 9e339bc..33a8d78 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# readabs 0.4.30 +* BREAKING CHANGE to read_cpi() in light of changes to the CPI (move to monthly collection). Now has a `frequency` argument that controls whether the quarterly or monthly data is returned. + # readabs 0.4.20 * Minor bug fixes diff --git a/R/read_cpi.R b/R/read_cpi.R index 0b94723..1322aa3 100644 --- a/R/read_cpi.R +++ b/R/read_cpi.R @@ -1,26 +1,22 @@ #' Download a tidy tibble containing the Consumer Price Index from the ABS #' #' \code{read_cpi()} uses the \code{read_abs()} function to download, import, -#' and tidy the Consumer Price Index from the ABS. It returns a tibble +#' and tidy the quarterly Consumer Price Index from the ABS. It returns a tibble #' containing two columns: the date and the CPI index value that corresponds #' to that date. This makes joining the CPI to another dataframe easy. #' \code{read_cpi()} returns the original (ie. not seasonally adjusted) #' all groups CPI for Australia. If you want the analytical series -#' (eg. seasonally adjusted CPI, or trimmed mean CPI), you can use +#' (eg. seasonally adjusted CPI, or trimmed mean CPI) or monthly series, you can use #' \code{read_abs()}. #' +#' By default, `read_abs()` retrieves the quarterly CPI. It can use the +#' `frequency` argument to change to monthly. +#' #' @param path character; default is "data/ABS". Only used if #' retain_files is set to TRUE. Local directory in which to save #' downloaded ABS time series spreadsheets. -#' -#' @param show_progress_bars logical; TRUE by default. If set to FALSE, progress -#' bars will not be shown when ABS spreadsheets are downloading. -#' -#' @param check_local logical; FALSE by default. See \code{?read_abs}. -#' -#' @param retain_files logical; FALSE by default. When TRUE, the spreadsheets -#' downloaded from the ABS website will be saved in the -#' directory specified with 'path'. +#' @param frequency Either `"quarterly"` (the default) or `"monthly"`. +#' @param ... Arguments passed to `read_abs()`. See `?read_abs` for details. #' #' @examples #' @@ -36,38 +32,28 @@ #' #' @export -read_cpi <- function(path = Sys.getenv("R_READABS_PATH", unset = tempdir()), - show_progress_bars = TRUE, - check_local = FALSE, - retain_files = FALSE) { - if (!is.logical(retain_files)) { - stop("`retain_files` must be either `TRUE` or `FALSE`.") - } +read_cpi <- function(frequency = c("quarterly", "monthly"), + path = Sys.getenv("R_READABS_PATH", unset = tempdir()), + ...) { - if (!is.logical(show_progress_bars)) { - stop("`show_progress_bars` must be either `TRUE` or `FALSE`") - } + frequency <- match.arg(frequency) + + cpi_series_id <- switch (frequency, + "quarterly" = "A2325846C", + "monthly" = "A130393720C" + ) - if (retain_files == TRUE & !is.character(path)) { - stop( - "If `retain_files` is `TRUE`,", - " you must specify a valid file path in `path`." - ) - } - cpi_raw <- read_abs( - cat_no = "6401.0", - tables = 1, - retain_files = retain_files, - check_local = check_local, - show_progress_bars = show_progress_bars, - path = path + cpi_raw <- read_abs_series( + series_id = cpi_series_id, + ... ) + series_name <- unique(cpi_raw$series) + + stopifnot(series_name == "Index Numbers ; All groups CPI ; Australia ;") + x <- cpi_raw %>% - dplyr::filter( - .data$series == "Index Numbers ; All groups CPI ; Australia ;" - ) %>% dplyr::select("date", "cpi" = "value" ) diff --git a/R/sysdata.rda b/R/sysdata.rda index 4aeef11..d078f86 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/man/download_abs_data_cube.Rd b/man/download_abs_data_cube.Rd index 18a2687..27cd9b3 100644 --- a/man/download_abs_data_cube.Rd +++ b/man/download_abs_data_cube.Rd @@ -62,9 +62,9 @@ download_abs_data_cube( } \seealso{ -Other data cube functions: -\code{\link{search_catalogues}()}, -\code{\link{show_available_catalogues}()}, -\code{\link{show_available_files}()} +Other data cube functions: +\code{\link[=search_catalogues]{search_catalogues()}}, +\code{\link[=show_available_catalogues]{show_available_catalogues()}}, +\code{\link[=show_available_files]{show_available_files()}} } \concept{data cube functions} diff --git a/man/read_cpi.Rd b/man/read_cpi.Rd index a739451..7cca917 100644 --- a/man/read_cpi.Rd +++ b/man/read_cpi.Rd @@ -5,36 +5,34 @@ \title{Download a tidy tibble containing the Consumer Price Index from the ABS} \usage{ read_cpi( + frequency = c("quarterly", "monthly"), path = Sys.getenv("R_READABS_PATH", unset = tempdir()), - show_progress_bars = TRUE, - check_local = FALSE, - retain_files = FALSE + ... ) } \arguments{ +\item{frequency}{Either \code{"quarterly"} (the default) or \code{"monthly"}.} + \item{path}{character; default is "data/ABS". Only used if retain_files is set to TRUE. Local directory in which to save downloaded ABS time series spreadsheets.} -\item{show_progress_bars}{logical; TRUE by default. If set to FALSE, progress -bars will not be shown when ABS spreadsheets are downloading.} - -\item{check_local}{logical; FALSE by default. See \code{?read_abs}.} - -\item{retain_files}{logical; FALSE by default. When TRUE, the spreadsheets -downloaded from the ABS website will be saved in the -directory specified with 'path'.} +\item{...}{Arguments passed to \code{read_abs()}. See \code{?read_abs} for details.} } \description{ \code{read_cpi()} uses the \code{read_abs()} function to download, import, -and tidy the Consumer Price Index from the ABS. It returns a tibble +and tidy the quarterly Consumer Price Index from the ABS. It returns a tibble containing two columns: the date and the CPI index value that corresponds to that date. This makes joining the CPI to another dataframe easy. \code{read_cpi()} returns the original (ie. not seasonally adjusted) all groups CPI for Australia. If you want the analytical series -(eg. seasonally adjusted CPI, or trimmed mean CPI), you can use +(eg. seasonally adjusted CPI, or trimmed mean CPI) or monthly series, you can use \code{read_abs()}. } +\details{ +By default, \code{read_abs()} retrieves the quarterly CPI. It can use the +\code{frequency} argument to change to monthly. +} \examples{ # Create a tibble called 'cpi' that contains the CPI index diff --git a/man/search_catalogues.Rd b/man/search_catalogues.Rd index 9369de4..3ebd561 100644 --- a/man/search_catalogues.Rd +++ b/man/search_catalogues.Rd @@ -31,9 +31,9 @@ a given string in the catalogue names, product title, and broad topic. search_catalogues("labour") } \seealso{ -Other data cube functions: -\code{\link{download_abs_data_cube}()}, -\code{\link{show_available_catalogues}()}, -\code{\link{show_available_files}()} +Other data cube functions: +\code{\link[=download_abs_data_cube]{download_abs_data_cube()}}, +\code{\link[=show_available_catalogues]{show_available_catalogues()}}, +\code{\link[=show_available_files]{show_available_files()}} } \concept{data cube functions} diff --git a/man/show_available_catalogues.Rd b/man/show_available_catalogues.Rd index 4eebc60..b89fb7d 100644 --- a/man/show_available_catalogues.Rd +++ b/man/show_available_catalogues.Rd @@ -25,9 +25,9 @@ These catalogues must be specified as a string as an argument to \code{download_ show_available_catalogues("Earnings and work hours") } \seealso{ -Other data cube functions: -\code{\link{download_abs_data_cube}()}, -\code{\link{search_catalogues}()}, -\code{\link{show_available_files}()} +Other data cube functions: +\code{\link[=download_abs_data_cube]{download_abs_data_cube()}}, +\code{\link[=search_catalogues]{search_catalogues()}}, +\code{\link[=show_available_files]{show_available_files()}} } \concept{data cube functions} diff --git a/man/show_available_files.Rd b/man/show_available_files.Rd index 2d0c8a3..3a6926e 100644 --- a/man/show_available_files.Rd +++ b/man/show_available_files.Rd @@ -40,14 +40,9 @@ show_available_files("labour-force-australia-detailed") } \seealso{ -Other data cube functions: -\code{\link{download_abs_data_cube}()}, -\code{\link{search_catalogues}()}, -\code{\link{show_available_catalogues}()} - -Other data cube functions: -\code{\link{download_abs_data_cube}()}, -\code{\link{search_catalogues}()}, -\code{\link{show_available_catalogues}()} +Other data cube functions: +\code{\link[=download_abs_data_cube]{download_abs_data_cube()}}, +\code{\link[=search_catalogues]{search_catalogues()}}, +\code{\link[=show_available_catalogues]{show_available_catalogues()}} } \concept{data cube functions} diff --git a/tests/testthat/test-readabs.R b/tests/testthat/test-readabs.R index 636669e..e126fe6 100644 --- a/tests/testthat/test-readabs.R +++ b/tests/testthat/test-readabs.R @@ -138,6 +138,13 @@ test_that("read_cpi() function downloads CPI index numbers", { cpi$cpi[cpi$date == date_12m_before_latest]) - 1 expect_gt(latest_annual_inflation, -.02) expect_lt(latest_annual_inflation, 0.1) + + # Test that default is quarterly + expect_equal(min(cpi$date), as.Date("1948-09-01")) + + cpi_m <- read_cpi("monthly") + expect_equal(min(cpi_m$date), as.Date("2024-04-01")) + }) test_that("read_cpi() returns appropriate errors", { @@ -147,7 +154,6 @@ test_that("read_cpi() returns appropriate errors", { expect_error(read_cpi(retain_files = NULL)) expect_error(read_cpi(show_progress_bars = NULL)) - expect_error(read_cpi(retain_files = TRUE, path = 1)) }) test_that("3401.0 table 1 can be loaded", {