Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down Expand Up @@ -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,
Expand All @@ -44,3 +43,4 @@ Suggests:
testthat (>= 2.1.0),
ggplot2
Roxygen: list(markdown = TRUE)
Config/roxygen2/version: 8.0.0
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
60 changes: 23 additions & 37 deletions R/read_cpi.R
Original file line number Diff line number Diff line change
@@ -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
#'
Expand All @@ -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"
)
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
8 changes: 4 additions & 4 deletions man/download_abs_data_cube.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions man/read_cpi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/search_catalogues.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/show_available_catalogues.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions man/show_available_files.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion tests/testthat/test-readabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -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", {
Expand Down
Loading