Skip to content

Commit

Permalink
Start improving examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Feb 2, 2024
1 parent e5ce5b1 commit 4481d80
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
46 changes: 44 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#'
#' ```
#'
#' See **Examples** section for an easy way to recode the numerical values into
#' [factors][base::factor].
#'
#' @format
#' [`data.frame`][data.frame()] with
#' `r prettyNum(nrow(igoR::igo_year_format3), big.mark=",")` rows. Relevant
Expand Down Expand Up @@ -60,8 +63,47 @@
#' datasets. *Journal of Peace Research, 57*(3), 492–503.
#' \doi{10.1177/0022343319881175}.
#' @examples
#'
#' data("igo_year_format3")
#' dplyr::tibble(igo_year_format3)
#'
#' # Show a glimpse
#' library(dplyr)
#'
#' igo_year_format3 %>%
#' select(ioname:angola) %>%
#' glimpse()
#'
#' # Recode numerical to factors with a small function
#' recode_category <- function(x) {
#' r <- dplyr::case_when(
#' x == 0 ~ "No Membership",
#' x == 1 ~ "Full Membership", x == 2 ~ "Associate Membership",
#' x == 3 ~ "Observer", x == -9 ~ "Missing Data",
#' x == -1 ~ "IGO Not In Existence", TRUE ~ NA
#' )
#'
#' factor(r,
#' levels = c(
#' "No Membership", "Full Membership", "Associate Membership", "Observer",
#' "Missing Data", "IGO Not In Existence", NA
#' ),
#' exclude = NULL
#' )
#' }
#'
#' # Take a sample
#'
#' sample_igo_year <- igo_year_format3 %>%
#' as_tibble() %>%
#' select(ioname:belgium)
#'
#' sample_igo_year %>% glimpse()
#'
#' # Recode
#' sample_igo_year_recoded <- sample_igo_year %>%
#' mutate(across(-c(ioname:year), recode_category))
#'
#' sample_igo_year_recoded %>% glimpse()
NULL

#' @title Country membership to IGO by year
Expand Down Expand Up @@ -190,5 +232,5 @@ NULL
#' @examples
#' # example code
#' data("states2016")
#' dplyr::tibble(states2016)
#' dplyr::glimpse(states2016)
NULL
45 changes: 44 additions & 1 deletion man/igo_year_format3.Rd

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

2 changes: 1 addition & 1 deletion man/states2016.Rd

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

0 comments on commit 4481d80

Please sign in to comment.