Skip to content

Commit

Permalink
lint Roxygen and code
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhsparks committed Dec 18, 2024
1 parent 377a4b0 commit c6d383f
Show file tree
Hide file tree
Showing 40 changed files with 154 additions and 149 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ VignetteBuilder:
knitr
Config/roxyglobals/filename: globals.R
Config/roxyglobals/unique: FALSE
Config/roxylint:list(linters = roxylint::tidy)
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE, roclets = c("collate", "namespace", "rd",
"roxyglobals::global_roclet"))
"roxyglobals::global_roclet", "roxylint::roxylint"))
RoxygenNote: 7.3.2
4 changes: 2 additions & 2 deletions R/clear_cache.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Remove Files in Users' Cache Directory
#' Remove files in users' cache directory
#'
#' Removes all files in the \pkg{read.abares} cache if any exist.
#'
Expand All @@ -8,7 +8,7 @@
#' clear_cache()
#' }
#' @family cache
#' @return Nothing, called for its side-effects, clearing the cached files
#' @return Nothing, called for its side-effects, clearing the cached files.
#' @export

clear_cache <- function() {
Expand Down
38 changes: 19 additions & 19 deletions R/get_agfd.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Get Australian Gridded Farm Data for Local Use
#' Get 'Australian Gridded Farm Data' (AGFD) for local use
#'
#' Downloads The Australian Gridded Farm Data (\acronym{AGFD}) data and unzips
#' the compressed files to NetCDF for importing.
Expand All @@ -13,7 +13,7 @@
#' These data have been produced by \acronym{ABARES} as part of the ongoing
#' Australian Agricultural Drought Indicator (\acronym{AADI}) project
#' (previously known as the Drought Early Warning System Project) and were
#' derived using \acronym{ABARES}
#' derived using \acronym{ABARES}'s
#' [*farmpredict*](https://www.agriculture.gov.au/abares/research-topics/climate/drought/farmpredict)
#' model, which in turn is based on ABARES Agricultural and Grazing Industries
#' Survey (\acronym{AAGIS}) data.\cr
Expand All @@ -35,18 +35,18 @@
#' Both sets of data are large in file size, *i.e.*, >1GB, and will require time
#' to download.
#'
#' @param fixed_prices `Boolean` Download historical climate and prices or
#' historical climate and fixed prices as described in (Hughes *et al.* 2022).
#' Defaults to `TRUE` and downloads the data with historical climate and fixed
#' prices \dQuote{to isolate the effects of climate variability on financial
#' incomes for broadacre farm businesses} (ABARES 2024). Using `TRUE` will
#' download simulations where global output and input price indexes are fixed
#' at values from the most recently completed financial year.
#' @param cache `Boolean` Cache the Australian Gridded Farm Data files after
#' download using [tools::R_user_dir] to identify the proper directory for
#' storing user data in a cache for this package. Defaults to `TRUE`, caching
#' the files locally. If `FALSE`, this function uses `tempdir()` and the files
#' are deleted upon closing of the \R session.
#' @param fixed_prices Download historical climate and prices or historical
#' climate and fixed prices as described in (Hughes *et al.* 2022). Defaults
#' to `TRUE` and downloads the data with historical climate and fixed prices
#' \dQuote{to isolate the effects of climate variability on financial incomes
#' for broadacre farm businesses} (ABARES 2024). Using `TRUE` will download
#' simulations where global output and input price indexes are fixed at values
#' from the most recently completed financial year.
#' @param cache Cache the Australian Gridded Farm Data files after download
#' using [tools::R_user_dir] to identify the proper directory for storing user
#' data in a cache for this package. Defaults to `TRUE`, caching the files
#' locally. If `FALSE`, this function uses `tempdir()` and the files are deleted
#' upon closing of the \R session.
#'
#' @section Model scenarios:
#'
Expand Down Expand Up @@ -173,7 +173,7 @@
#' get_agfd()
#'
#' @return A `read.abares.agfd.nc.files` object, a `list` of NetCDF files
#' containing the Australian Gridded Farm Data
#' containing the Australian Gridded Farm Data.
#' @family AGFD
#' @autoglobal
#' @export
Expand Down Expand Up @@ -233,12 +233,12 @@ get_agfd <- function(fixed_prices = TRUE,
return(agfd_nc)
}

#' Prints read.abares.agfd.nc.files Objects
#' Prints read.abares.agfd.nc.files objects
#'
#' Custom [print()] method for `read.abares.agfd.nc.files` objects.
#'
#' @param x a `read.abares.agfd.nc.files` object
#' @param ... ignored
#' @param x a `read.abares.agfd.nc.files` object.
#' @param ... ignored.
#' @export
#' @autoglobal
#' @noRd
Expand All @@ -249,7 +249,7 @@ print.read.abares.agfd.nc.files <- function(x, ...) {
invisible(x)
}

#' Prints File Format Information for the AGFD NetCDF Files
#' Prints file format information for the AGFD NetCDF files
#'
#' Print the file format from section 3.2 in \cite{Australian Bureau of
#' Agricultural and Resource Economics and Sciences}.
Expand Down
28 changes: 14 additions & 14 deletions R/get_soil_thickness.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Get Soil Thickness for Australian Areas of Intensive Agriculture of Layer 1 for Local Use
#' Get soil thickness for 'Australian Areas of Intensive Agriculture of Layer 1' for local use
#'
#' @param cache `Boolean` Cache the soil thickness data files after download
#' @param cache Caches the soil thickness data files after download
#' using `tools::R_user_dir()` to identify the proper directory for storing
#' user data in a cache for this package. Defaults to `TRUE`, caching the files
#' locally. If `FALSE`, this function uses `tempdir()` and the files are deleted
Expand All @@ -25,7 +25,7 @@
#'
#' @return A `read.abares.soil.thickness` object, which is a named `list` with
#' the file path of the resulting \acronym{ESRI} Grid file and text file of
#' metadata
#' metadata.
#'
#' @references <https://data.agriculture.gov.au/geonetwork/srv/eng/catalog.search#/metadata/faa9f157-8e17-4b23-b6a7-37eb7920ead6>
#' @source <https://anrdl-integration-web-catalog-saxfirxkxt.s3-ap-southeast-2.amazonaws.com/warehouse/staiar9cl__059/staiar9cl__05911a01eg_geo___.zip>
Expand All @@ -46,13 +46,13 @@ get_soil_thickness <- function(cache = TRUE) {
}
}

#' Create a Object of read.abares.soil.thickness.files
#' Create a object of read.abares.soil.thickness.files
#'
#' @param dir File where files have been downloaded
#' @param dir File where files have been downloaded.
#'
#' @return A `read.abares.soil.thickness` object, which is a named `list` with
#' the file path of the resulting \acronym{ESRI} Grid file and text file of
#' metadata
#' metadata.
#' @noRd
#' @keywords Internal

Expand All @@ -72,15 +72,15 @@ get_soil_thickness <- function(cache = TRUE) {
return(soil_thickness)
}

#' Downloads Soil Thickness Data if Not Located Locally
#' Downloads soil thickness data if not already found locally
#' @param cache `Boolean` Cache the soil thickness data files after download
#' using `tools::R_user_dir()` to identify the proper directory for storing
#' user data in a cache for this package. Defaults to `TRUE`, caching the files
#' locally. If `FALSE`, this function uses `tempdir()` and the files are deleted
#' upon closing of the \R session.
#'
#' @return Nothing, called for its side-effects of downloading and unzipping
#' files
#' files.
#'
#' @noRd
#' @keywords Internal
Expand Down Expand Up @@ -124,12 +124,12 @@ get_soil_thickness <- function(cache = TRUE) {
return(invisible(NULL))
}

#' Prints read.abares.soil.thickness.files Object
#' Prints read.abares.soil.thickness.files object
#'
#' Custom [print()] method for `read.abares.soil.thickness.files` objects.
#'
#' @param x a `read.abares.soil.thickness.files` object
#' @param ... ignored
#' @param x a `read.abares.soil.thickness.files` object.
#' @param ... ignored.
#' @export
#' @noRd
print.read.abares.soil.thickness.files <- function(x, ...) {
Expand Down Expand Up @@ -168,18 +168,18 @@ print.read.abares.soil.thickness.files <- function(x, ...) {
invisible(x)
}

#' Display Complete Metadata Associated with Soil Thickness Data in the \R Console
#' Display complete metadata associated with soil thickness data
#'
#' Displays the complete set of metadata associated with the soil thickness
#' data in your \R console. For including the metadata in documents or other
#' methods outside of \R, see [get_soil_thickness] for an example using
#' [pander::pander] to print the metadata.
#'
#'
#' @param x A `read.abares.soil.thickness.files` object
#' @param x A `read.abares.soil.thickness.files` object.
#'
#' @return Nothing, called for its side effects, it prints the complete
#' metadata file to the \R console
#' metadata file to the \R console.
#' @examplesIf interactive()
#' get_soil_thickness(cache = TRUE) |>
#' print_soil_thickness_metadata()
Expand Down
23 changes: 12 additions & 11 deletions R/internal_functions.R
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
#' Find the File Path to Users' Cache Directory
#' Find the file path to the users' cache directory
#'
#' @return A `character` string value of a file path indicating the proper
#' directory to use for cached files
#' directory to use for cached files.
#' @noRd
#' @keywords Internal
#' @autoglobal
.find_user_cache <- function() {
tools::R_user_dir(package = "read.abares", which = "cache")
}

#' Check for read.abares.something S3 Class
#' Check for read.abares.something S3 class
#'
#' @param x An object for validating
#' @param class An S3 class to validate against
#' @param x An object for validating.
#' @param class An S3 class to validate against.
#'
#' @return Nothing, called for its side-effects of class validation
#' @return Nothing, called for its side-effects of class validation.
#' @keywords Internal
#' @autoglobal
#' @noRd

.check_class <- function(x, class) {
if (missing(x) || !inherits(x, class)) {
cli::cli_abort("You must provide a {.code read.abares} class object.",
call = rlang::caller_env())
call = rlang::caller_env()
)
}
}

#' Use httr2 to Fetch a File With Retries
#' Use httr2 to fetch a file with retries
#'
#' Retries to download the requested resource before stopping. Uses
#' \CRANpkg{httr2} to cache in-session results in the `tempdir()`.
#'
#' @param url `Character` The URL being requested
#' @param .f `Character` A filepath to be written to local storage
#' @param url `Character` The URL being requested.
#' @param .f `Character` A filepath to be written to local storage.
#' @param .max_tries `Integer` The number of times to retry a failed download
#' before emitting an error message
#' before emitting an error message.
#' @param .initial_delay `Integer` The number of seconds to delay before
#' retrying the download. This increases as the tries increment.
#'
Expand Down
12 changes: 6 additions & 6 deletions R/read_aagis_regions.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Read AAGIS Region Mapping Files
#' Read 'Australian Agricultural and Grazing Industries Survey' (AAGIS) region mapping files
#'
#' Download, cache and import the Australian Agricultural and Grazing
#' Industries Survey (\acronym{AAGIS} regions geospatial shapefile. Upon
Expand All @@ -17,7 +17,7 @@
#'
#' plot(aagis)
#'
#' @return An \CRANpkg{sf} object of the \acronym{AAGIS} regions
#' @return An \CRANpkg{sf} object of the \acronym{AAGIS} regions.
#'
#' @family AGFD
#'
Expand All @@ -35,14 +35,14 @@ read_aagis_regions <- function(cache = TRUE) {
}
}

#' Check for Pre-existing File Before Downloading
#' Check for a pre-existing file before downloading
#'
#' Checks the user cache first, then `tempdir()` for the files before
#' returning a `NULL` value. If `cache == TRUE` and the file is not in the user
#' cache, but is in `tempdir()`, it is saved to the cache before being returned
#' in the current session.
#'
#' @return An \cranpkg{sf} object of AAGIS regions
#' @return An \cranpkg{sf} object of AAGIS regions.
#' @noRd
#' @autoglobal
#' @keywords Internal
Expand All @@ -67,7 +67,7 @@ read_aagis_regions <- function(cache = TRUE) {
}
}

#' Download the AAGIS Regions Shapefile
#' Download the 'Australian Agricultural and Grazing Industries Survey' (AAGIS) regions shapefile
#'
#' Handles downloading, caching (if requested) and importing of AAGIS regions
#' geospatial data. The geometries are corrected for validity before returning
Expand All @@ -80,7 +80,7 @@ read_aagis_regions <- function(cache = TRUE) {
#' function uses `tempdir()` and the files are deleted upon closing of the \R
#' session.
#'
#' @return An \cranpkg{sf} object of AAGIS regions
#' @return An \cranpkg{sf} object of AAGIS regions.
#' @noRd
#' @autoglobal
#' @keywords Internal
Expand Down
6 changes: 3 additions & 3 deletions R/read_abares_trade.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Read Data From the ABARES Trade Dashboard
#' Read data from the ABARES Trade Dashboard
#'
#' Fetches and imports \acronym{ABARES} trade data.
#'
Expand Down Expand Up @@ -37,7 +37,7 @@ read_abares_trade <- function(cache = TRUE) {
}
}

#' Download the ABARES Trade CSV File
#' Download the ABARES trade CSV file
#'
#' Handles downloading and caching (if requested) of ABARES Trade data files.
#'
Expand All @@ -47,7 +47,7 @@ read_abares_trade <- function(cache = TRUE) {
#' the files locally as a native \R object. If `FALSE`, this function uses
#' `tempdir()` and the files are deleted upon closing of the \R session.
#'
#' @return A \CRANpkg{data.table} object of the \acronym{ABARES} trade data
#' @return A \CRANpkg{data.table} object of the \acronym{ABARES} trade data.
#' @noRd
#' @autoglobal
#' @keywords Internal
Expand Down
8 changes: 4 additions & 4 deletions R/read_abares_trade_regions.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Read ABARES Trade Data Regions From the ABARES Trade Dashboard
#' Read ABARES 'Trade Data Regions' from the ABARES Trade Dashboard
#'
#' Fetches and imports \acronym{ABARES} trade regions data.
#'
Expand Down Expand Up @@ -42,7 +42,7 @@ read_abares_trade_regions <- function(cache = TRUE) {
#' in the current session.
#'
#'
#' @return A \CRANpkg{data.table} object of the \acronym{ABARES} trade data
#' @return A \CRANpkg{data.table} object of the \acronym{ABARES} trade data.
#' @noRd
#' @autoglobal
#' @keywords Internal
Expand Down Expand Up @@ -71,7 +71,7 @@ read_abares_trade_regions <- function(cache = TRUE) {
}
}

#' Download the ABARES Trade CSV File
#' Download the ABARES Trade CSV file
#'
#' Handles downloading and caching (if requested) of ABARES Trade data files.
#'
Expand All @@ -81,7 +81,7 @@ read_abares_trade_regions <- function(cache = TRUE) {
#' the files locally as a native \R object. If `FALSE`, this function uses
#' `tempdir()` and the files are deleted upon closing of the \R session.
#'
#' @return A \CRANpkg{data.table} object of the \acronym{ABARES} trade data
#' @return A \CRANpkg{data.table} object of the \acronym{ABARES} trade data.
#' @noRd
#' @autoglobal
#' @keywords Internal
Expand Down
7 changes: 4 additions & 3 deletions R/read_agfd_dt.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Read AGFD NCDF Files as a data.table
#' Read 'Australian Gridded Farm Data' (AGFD) NCDF files as a data.table
#'
#' Read Australian Gridded Farm Data, (\acronym{AGFD}) as a [data.table] object.
#'
Expand All @@ -7,9 +7,10 @@
#' @inheritSection get_agfd Data files
#' @inheritSection get_agfd Data layers
#' @inherit get_agfd references
#' @param files A list of \acronym{AGFD} NetCDF files to import
#' @param files A list of \acronym{AGFD} NetCDF files to import.
#'
#' @return a [data.table::data.table] object of the Australian Gridded Farm Data
#' @return a [data.table::data.table] object of the 'Australian Gridded Farm
#' Data'.
#'
#' @examplesIf interactive()
#'
Expand Down
6 changes: 3 additions & 3 deletions R/read_agfd_stars.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Read AGFD NCDF Files With stars
#' Read 'Australian Gridded Farm Data' (AGFD) NCDF files with stars
#'
#' Read Australian Gridded Farm Data, (\acronym{AGFD}) as a list of [stars]
#' Read 'Australian Gridded Farm Data', (\acronym{AGFD}) as a list of [stars]
#' objects.
#'
#' @inherit get_agfd details
Expand All @@ -11,7 +11,7 @@
#' @inherit get_agfd references
#'
#' @return a `list` object of \CRANpkg{stars} objects of the Australian Gridded
#' Farm Data with the file names as the list's objects' names
#' Farm Data with the file names as the list's objects' names.
#'
#' @examplesIf interactive()
#'
Expand Down
Loading

0 comments on commit c6d383f

Please sign in to comment.