Skip to content

Commit

Permalink
Use @examplesIf and move r2dii.match back into Suggests (#463)
Browse files Browse the repository at this point in the history
* use r2dii.match in `Suggests`

* Use exampleIf in roxygen

* document
  • Loading branch information
jdhoffa authored Feb 1, 2024
1 parent 1ebca1e commit 560345a
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 244 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ Imports:
lifecycle,
magrittr,
r2dii.data (>= 0.4.0),
r2dii.match,
rlang (>= 0.1.2),
tidyr,
tidyselect,
zoo
Suggests:
covr,
r2dii.match,
rmarkdown,
roxygen2,
spelling,
Expand Down
30 changes: 12 additions & 18 deletions R/join_abcd_scenario.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,20 @@
#'
#' @family utility functions
#'
#' @examples
#' installed <- requireNamespace("r2dii.data", quietly = TRUE) &&
#' requireNamespace("r2dii.match", versionCheck = "0.1.0", quietly = TRUE) &&
#' packageVersion("r2dii.match") >= "0.1.0"
#' @examplesIf rlang::is_installed("r2dii.data") && rlang::is_installed("r2dii.match", version = "0.1.0)
#' library(r2dii.data)
#' library(r2dii.match)
#'
#' if (installed) {
#' library(r2dii.data)
#' library(r2dii.match)
#' valid_matches <- match_name(loanbook_demo, abcd_demo) %>%
#' # WARNING: Remember to validate matches (see `?prioritize`)
#' prioritize()
#'
#' valid_matches <- match_name(loanbook_demo, abcd_demo) %>%
#' # WARNING: Remember to validate matches (see `?prioritize`)
#' prioritize()
#'
#' valid_matches %>%
#' join_abcd_scenario(
#' abcd = abcd_demo,
#' scenario = scenario_demo_2020,
#' region_isos = region_isos_demo
#' )
#' }
#' valid_matches %>%
#' join_abcd_scenario(
#' abcd = abcd_demo,
#' scenario = scenario_demo_2020,
#' region_isos = region_isos_demo
#' )
join_abcd_scenario <- function(data,
abcd,
scenario,
Expand Down
42 changes: 17 additions & 25 deletions R/summarize_weighted_production.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,29 @@
#' `weighted_production` for `summarize_weighted_production()` and
#' `summarize_weighted_percent_change()`, respectively.
#'
#' @examples
#' \dontrun{
#' installed <- requireNamespace("r2dii.data", quietly = TRUE) &&
#' requireNamespace("r2dii.match", quietly = TRUE) &&
#' packageVersion("r2dii.match") >= "0.1.0"
#' @examplesIf rlang::is_installed("r2dii.data") && rlang::is_installed("r2dii.match", version = "0.1.0)
#' library(r2dii.data)
#' library(r2dii.match)
#'
#' if (installed) {
#' library(r2dii.data)
#' library(r2dii.match)
#'
#' loanbook <- head(loanbook_demo, 150)
#' abcd <- head(abcd_demo, 100)
#' master <- loanbook %>%
#' match_name(abcd) %>%
#' prioritize() %>%
#' join_abcd_scenario(
#' abcd = abcd,
#' scenario = scenario_demo_2020,
#' region_isos = region_isos_demo
#' loanbook <- head(loanbook_demo, 150)
#' abcd <- head(abcd_demo, 100)
#' master <- loanbook %>%
#' match_name(abcd) %>%
#' prioritize() %>%
#' join_abcd_scenario(
#' abcd = abcd,
#' scenario = scenario_demo_2020,
#' region_isos = region_isos_demo
#' ) %>%
#' dplyr::filter(production != 0)
#' dplyr::filter(production != 0)
#'
#' summarize_weighted_production(master)
#' summarize_weighted_production(master)
#'
#' summarize_weighted_production(master, use_credit_limit = TRUE)
#' summarize_weighted_production(master, use_credit_limit = TRUE)
#'
#' summarize_weighted_percent_change(master)
#' summarize_weighted_percent_change(master)
#'
#' summarize_weighted_percent_change(master, use_credit_limit = TRUE)
#' }
#' }
#' summarize_weighted_percent_change(master, use_credit_limit = TRUE)
summarize_weighted_production <- function(data, ..., use_credit_limit = FALSE) {
summarize_weighted_production_(data, ..., use_credit_limit = use_credit_limit, with_targets = FALSE)
}
Expand Down
65 changes: 29 additions & 36 deletions R/target_market_share.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,43 @@
#'
#' @family functions to calculate scenario targets
#'
#' @examples
#' \dontrun{
#' installed <- requireNamespace("r2dii.data", quietly = TRUE) &&
#' requireNamespace("r2dii.match", quietly = TRUE) &&
#' packageVersion("r2dii.match") >= "0.1.0"
#' @examplesIf rlang::is_installed("r2dii.data") && rlang::is_installed("r2dii.match", version = "0.1.0)
#'
#' if (installed) {
#' library(r2dii.data)
#' library(r2dii.match)
#' library(r2dii.data)
#' library(r2dii.match)
#'
#' loanbook <- head(loanbook_demo, 100)
#' abcd <- head(abcd_demo, 100)
#' loanbook <- head(loanbook_demo, 100)
#' abcd <- head(abcd_demo, 100)
#'
#' matched <- loanbook %>%
#' match_name(abcd) %>%
#' prioritize()
#' matched <- loanbook %>%
#' match_name(abcd) %>%
#' prioritize()
#'
#' # Calculate targets at portfolio level
#' matched %>%
#' target_market_share(
#' abcd = abcd,
#' scenario = scenario_demo_2020,
#' region_isos = region_isos_demo
#' # Calculate targets at portfolio level
#' matched %>%
#' target_market_share(
#' abcd = abcd,
#' scenario = scenario_demo_2020,
#' region_isos = region_isos_demo
#' )
#'
#' # Calculate targets at company level
#' matched %>%
#' target_market_share(
#' abcd = abcd,
#' scenario = scenario_demo_2020,
#' region_isos = region_isos_demo,
#' by_company = TRUE
#' )
#' # Calculate targets at company level
#' matched %>%
#' target_market_share(
#' abcd = abcd,
#' scenario = scenario_demo_2020,
#' region_isos = region_isos_demo,
#' by_company = TRUE
#' )
#'
#' matched %>%
#' target_market_share(
#' abcd = abcd,
#' scenario = scenario_demo_2020,
#' region_isos = region_isos_demo,
#' # Calculate unweighted targets
#' weight_production = FALSE
#' matched %>%
#' target_market_share(
#' abcd = abcd,
#' scenario = scenario_demo_2020,
#' region_isos = region_isos_demo,
#' # Calculate unweighted targets
#' weight_production = FALSE
#' )
#' }
#' }
target_market_share <- function(data,
abcd,
scenario,
Expand Down
53 changes: 23 additions & 30 deletions R/target_sda.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,34 @@
#'
#' @family functions to calculate scenario targets
#'
#' @examples
#' \dontrun{
#' installed <- requireNamespace("r2dii.match", quietly = TRUE) &&
#' requireNamespace("r2dii.data", quietly = TRUE) &&
#' packageVersion("r2dii.match") >= "0.1.0"
#' @examplesIf rlang::is_installed("r2dii.data") && rlang::is_installed("r2dii.match", version = "0.1.0)
#'
#' if (installed) {
#' library(r2dii.match)
#' library(r2dii.data)
#' library(r2dii.match)
#' library(r2dii.data)
#'
#' loanbook <- head(loanbook_demo, 150)
#' abcd <- head(abcd_demo, 100)
#' loanbook <- head(loanbook_demo, 150)
#' abcd <- head(abcd_demo, 100)
#'
#' matched <- loanbook %>%
#' match_name(abcd) %>%
#' prioritize()
#' matched <- loanbook %>%
#' match_name(abcd) %>%
#' prioritize()
#'
#' # Calculate targets at portfolio level
#' matched %>%
#' target_sda(
#' abcd = abcd,
#' co2_intensity_scenario = co2_intensity_scenario_demo,
#' region_isos = region_isos_demo
#' )
#' # Calculate targets at portfolio level
#' matched %>%
#' target_sda(
#' abcd = abcd,
#' co2_intensity_scenario = co2_intensity_scenario_demo,
#' region_isos = region_isos_demo
#' )
#'
#' # Calculate targets at company level
#' matched %>%
#' target_sda(
#' abcd = abcd,
#' co2_intensity_scenario = co2_intensity_scenario_demo,
#' region_isos = region_isos_demo,
#' by_company = TRUE
#' )
#' }
#' }
#' # Calculate targets at company level
#' matched %>%
#' target_sda(
#' abcd = abcd,
#' co2_intensity_scenario = co2_intensity_scenario_demo,
#' region_isos = region_isos_demo,
#' by_company = TRUE
#' )
target_sda <- function(data,
abcd,
co2_intensity_scenario,
Expand Down
21 changes: 0 additions & 21 deletions man/join_abcd_scenario.Rd

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

32 changes: 0 additions & 32 deletions man/summarize_weighted_production.Rd

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

45 changes: 0 additions & 45 deletions man/target_market_share.Rd

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

Loading

0 comments on commit 560345a

Please sign in to comment.