Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor function names #72

Merged
merged 11 commits into from
Dec 18, 2024
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
14 changes: 7 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

S3method(print,elic_cat)
S3method(print,elic_cont)
export(cat_add_data)
export(cat_get_data)
export(cat_sample_data)
export(elic_cat_add_data)
export(elic_cat_get_data)
export(elic_cat_start)
export(elic_cont_add_data)
export(elic_cont_get_data)
export(elic_cont_plot)
export(elic_cont_start)
export(cat_start)
export(cont_add_data)
export(cont_get_data)
export(cont_plot)
export(cont_start)
importFrom(cli,cli_abort)
importFrom(cli,cli_h2)
importFrom(cli,cli_li)
Expand Down
135 changes: 68 additions & 67 deletions R/cat_add_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' `elic_cat_add_data()` adds data to an [elic_cat] object from different
#' sources.
#' `cat_add_data()` adds data to an [elic_cat] object from different sources.
#'
#' @param x an object of class [elic_cat].
#' @param mechanism character string that indicates the machanism to which the
#' data belongs.
#' @inheritParams elic_cont_add_data
#' @inheritParams cont_add_data
#'
#' @section Data format:
#'
Expand All @@ -33,9 +32,10 @@
#' * The final column should be the estimates of each expert for each site and
#' impact level.
#'
#' The name of the columns is not important, `elic_cat_add_data()` will
#' overwrite them according to the following convention:
#' * The first column will be renamed `id`, the second column `level`, the third
#' The name of the columns is not important, `cat_add_data()` will overwrite
#' them according to the following convention:
#'
#' The first column will be renamed `id`, the second column `level`, the third
#' column `site`, the fourth column `confidence`, and the fifth column
#' `estimate`.
#'
Expand Down Expand Up @@ -79,94 +79,95 @@
#' my_levels <- c("level_1", "level_2", "level_3", "level_4", "level_5")
#' my_sites <- c("site_1", "site_2", "site_3", "site_4")
#' my_mechanisms <- c("mechanism_1", "mechanism_2", "mechanism_3")
#' x <- elic_cat_start(levels = my_levels,
#' sites = my_sites,
#' experts = 6,
#' mechanisms = my_mechanisms)
#' x <- cat_start(levels = my_levels,
#' sites = my_sites,
#' experts = 6,
#' mechanisms = my_mechanisms)
#'
#' # Add data for the three mechanisms from a data.frame. Notice that the
#' # three commands can be piped
#' my_elicit <- elic_cat_add_data(x,
#' data_source = mechanism_1,
#' mechanism = "mechanism_1") |>
#' elic_cat_add_data(data_source = mechanism_2, mechanism = "mechanism_2") |>
#' elic_cat_add_data(data_source = mechanism_3, mechanism = "mechanism_3")
#' my_elicit <- cat_add_data(x,
#' data_source = mechanism_1,
#' mechanism = "mechanism_1") |>
#' cat_add_data(data_source = mechanism_2, mechanism = "mechanism_2") |>
#' cat_add_data(data_source = mechanism_3, mechanism = "mechanism_3")
#' my_elicit
#'
#' # Add data for the first and second round from a csv file
#' files <- list.files(path = system.file("extdata", package = "elicitr"),
#' pattern = "mechanism_",
#' full.names = TRUE)
#' my_elicit <- elic_cat_add_data(x,
#' data_source = files[1],
#' mechanism = "mechanism_1") |>
#' elic_cat_add_data(data_source = files[2], mechanism = "mechanism_2") |>
#' elic_cat_add_data(data_source = files[3], mechanism = "mechanism_3")
#' my_elicit <- cat_add_data(x,
#' data_source = files[1],
#' mechanism = "mechanism_1") |>
#' cat_add_data(data_source = files[2], mechanism = "mechanism_2") |>
#' cat_add_data(data_source = files[3], mechanism = "mechanism_3")
#' my_elicit
#'
#' # Add data for the first and second round from a xlsx file with three sheets
#' file <- list.files(path = system.file("extdata", package = "elicitr"),
#' pattern = "mechanisms",
#' full.names = TRUE)
#' # Using the sheet index
#' my_elicit <- elic_cat_add_data(x,
#' data_source = file,
#' sheet = 1,
#' mechanism = "mechanism_1") |>
#' elic_cat_add_data(data_source = file,
#' sheet = 2,
#' mechanism = "mechanism_2") |>
#' elic_cat_add_data(data_source = file,
#' sheet = 3,
#' mechanism = "mechanism_3")
#' my_elicit <- cat_add_data(x,
#' data_source = file,
#' sheet = 1,
#' mechanism = "mechanism_1") |>
#' cat_add_data(data_source = file,
#' sheet = 2,
#' mechanism = "mechanism_2") |>
#' cat_add_data(data_source = file,
#' sheet = 3,
#' mechanism = "mechanism_3")
#' my_elicit
#' # Using the sheet name
#' my_elicit <- elic_cat_add_data(x, data_source = file,
#' sheet = "Mechanism 1",
#' mechanism = "mechanism_1") |>
#' elic_cat_add_data(data_source = file,
#' sheet = "Mechanism 2",
#' mechanism = "mechanism_2") |>
#' elic_cat_add_data(data_source = file,
#' sheet = "Mechanism 3",
#' mechanism = "mechanism_3")
#' my_elicit <- cat_add_data(x,
#' data_source = file,
#' sheet = "Mechanism 1",
#' mechanism = "mechanism_1") |>
#' cat_add_data(data_source = file,
#' sheet = "Mechanism 2",
#' mechanism = "mechanism_2") |>
#' cat_add_data(data_source = file,
#' sheet = "Mechanism 3",
#' mechanism = "mechanism_3")
#' my_elicit
#'
#' @examplesIf interactive()
#' # Add data for the first and second round from Google Sheets
#' googlesheets4::gs4_deauth()
#' gs <- "18VHeHB89P1s-6banaVoqOP-ggFmQZYx-z_31nMffAb8"
#' # Using the sheet index
#' my_elicit <- elic_cat_add_data(x,
#' data_source = gs,
#' sheet = 1,
#' mechanism = "mechanism_1") |>
#' elic_cat_add_data(data_source = gs,
#' sheet = 2,
#' mechanism = "mechanism_2") |>
#' elic_cat_add_data(data_source = gs,
#' sheet = 3,
#' mechanism = "mechanism_3")
#' my_elicit <- cat_add_data(x,
#' data_source = gs,
#' sheet = 1,
#' mechanism = "mechanism_1") |>
#' cat_add_data(data_source = gs,
#' sheet = 2,
#' mechanism = "mechanism_2") |>
#' cat_add_data(data_source = gs,
#' sheet = 3,
#' mechanism = "mechanism_3")
#' my_elicit
#' # Using the sheet name
#' my_elicit <- elic_cat_add_data(x, data_source = gs,
#' sheet = "Mechanism 1",
#' mechanism = "mechanism_1") |>
#' elic_cat_add_data(data_source = gs,
#' sheet = "Mechanism 2",
#' mechanism = "mechanism_2") |>
#' elic_cat_add_data(data_source = gs,
#' sheet = "Mechanism 3",
#' mechanism = "mechanism_3")
#' my_elicit <- cat_add_data(x, data_source = gs,
#' sheet = "Mechanism 1",
#' mechanism = "mechanism_1") |>
#' cat_add_data(data_source = gs,
#' sheet = "Mechanism 2",
#' mechanism = "mechanism_2") |>
#' cat_add_data(data_source = gs,
#' sheet = "Mechanism 3",
#' mechanism = "mechanism_3")
#' my_elicit
elic_cat_add_data <- function(x,
data_source,
mechanism,
...,
sep = ",",
sheet = 1,
overwrite = FALSE,
verbose = TRUE) {
cat_add_data <- function(x,
data_source,
mechanism,
...,
sep = ",",
sheet = 1,
overwrite = FALSE,
verbose = TRUE) {

# Check if the object is of class elic_cat
check_elic_obj(x, type = "cat")
Expand Down Expand Up @@ -354,7 +355,7 @@ check_column_format <- function(x, col) {

error <- "The column containing the {what} is not formatted as \\
expected."
info <- "See Data format in {.fn elicitr::elic_cat_add_data}."
info <- "See Data format in {.fn elicitr::cat_add_data}."

cli::cli_abort(c("Malformatted dataset:",
"x" = error,
Expand Down
34 changes: 17 additions & 17 deletions R/cat_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#'
#' Get data from an [elic_cat] object.
#'
#' @inheritParams elic_cat_add_data
#' @inheritParams cat_add_data
#' @param site character string with the name of the site or character vector
#' with the sites that you want to extract from the data. Use `all` for all
#' sites.
Expand All @@ -24,29 +24,29 @@
#' my_levels <- c("level_1", "level_2", "level_3", "level_4", "level_5")
#' my_sites <- c("site_1", "site_2", "site_3", "site_4")
#' my_mechanisms <- c("mechanism_1", "mechanism_2", "mechanism_3")
#' my_elicit <- elic_cat_start(levels = my_levels,
#' sites = my_sites,
#' experts = 6,
#' mechanisms = my_mechanisms) |>
#' elic_cat_add_data(data_source = mechanism_1, mechanism = "mechanism_1") |>
#' elic_cat_add_data(data_source = mechanism_2, mechanism = "mechanism_2") |>
#' elic_cat_add_data(data_source = mechanism_3, mechanism = "mechanism_3")
#' my_elicit <- cat_start(levels = my_levels,
#' sites = my_sites,
#' experts = 6,
#' mechanisms = my_mechanisms) |>
#' cat_add_data(data_source = mechanism_1, mechanism = "mechanism_1") |>
#' cat_add_data(data_source = mechanism_2, mechanism = "mechanism_2") |>
#' cat_add_data(data_source = mechanism_3, mechanism = "mechanism_3")
#'
#' # Get all data from Mechanism 1
#' elic_cat_get_data(my_elicit, mechanism = "mechanism_1")
#' cat_get_data(my_elicit, mechanism = "mechanism_1")
#'
#' # Get data by site name----
#' # Get data for site_1 from Mechanism 2
#' elic_cat_get_data(my_elicit, mechanism = "mechanism_2", site = "site_1")
#' cat_get_data(my_elicit, mechanism = "mechanism_2", site = "site_1")
#'
#' # Get data for site_1 and site_3 from Mechanism 3
#' elic_cat_get_data(my_elicit,
#' mechanism = "mechanism_3",
#' site = c("site_1", "site_3"))
elic_cat_get_data <- function(x,
mechanism,
...,
site = "all") {
#' cat_get_data(my_elicit,
#' mechanism = "mechanism_3",
#' site = c("site_1", "site_3"))
cat_get_data <- function(x,
mechanism,
...,
site = "all") {

# Check if the object is of class elic_cat
check_elic_obj(x, type = "cat")
Expand Down
24 changes: 14 additions & 10 deletions R/cat_sample_data.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#' Sample categorical data
#'
#' Sample data based on expert estimates stored in the [`elic_cat`] object.
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' @inheritParams elic_cat_get_data
#' `cat_sample_data()` samples data based on expert estimates stored in the
#' [`elic_cat`] object.
#'
#' @inheritParams cat_get_data
#' @param method character string with the name of the method to sample the
#' data. The available methods are: _basic_ and _bootstrap_, see Methods below.
#' @param n_votes numeric indicating the number of votes to consider, used only
Expand Down Expand Up @@ -47,13 +51,13 @@
#' my_levels <- c("level_1", "level_2", "level_3", "level_4", "level_5")
#' my_sites <- c("site_1", "site_2", "site_3", "site_4")
#' my_mechanisms <- c("mechanism_1", "mechanism_2", "mechanism_3")
#' my_elicit <- elic_cat_start(levels = my_levels,
#' sites = my_sites,
#' experts = 6,
#' mechanisms = my_mechanisms) |>
#' elic_cat_add_data(data_source = mechanism_1, mechanism = "mechanism_1") |>
#' elic_cat_add_data(data_source = mechanism_2, mechanism = "mechanism_2") |>
#' elic_cat_add_data(data_source = mechanism_3, mechanism = "mechanism_3")
#' my_elicit <- cat_start(levels = my_levels,
#' sites = my_sites,
#' experts = 6,
#' mechanisms = my_mechanisms) |>
#' cat_add_data(data_source = mechanism_1, mechanism = "mechanism_1") |>
#' cat_add_data(data_source = mechanism_2, mechanism = "mechanism_2") |>
#' cat_add_data(data_source = mechanism_3, mechanism = "mechanism_3")
#'
#' # Sample data from Mechanism 1 for all sites using the basic method
#' samp <- cat_sample_data(my_elicit,
Expand Down Expand Up @@ -83,7 +87,7 @@ cat_sample_data <- function(x,
check_method(x, method)

# Get data
data <- elic_cat_get_data(x, mechanism = mechanism, site = site)
data <- cat_get_data(x, mechanism = mechanism, site = site)

experts <- unique(data[["id"]])
levels <- unique(data[["level"]])
Expand Down
40 changes: 20 additions & 20 deletions R/cat_start.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' `elic_cat_start()` initialises an [elic_cat] object which stores important
#' `cat_start()` initialises an [elic_cat] object which stores important
#' metadata for the data collected during the elicitation process of categorical
#' data.
#'
Expand All @@ -16,13 +16,13 @@
#' more.
#' @param mechanisms character vector with the names of the mechanisms of impact
#' investigated.
#' @inheritParams elic_cont_start
#' @inheritParams cont_start
#'
#' @section Levels:
#'
#' Levels are inherited between mechanisms. A minimum of two levels are needed.
#' If only one level is investigated, please refer to the functions for the
#' elicitation of continuous data (e.g. [elic_cont_start]).
#' elicitation of continuous data (e.g. [cont_start]).
#'
#' @section Sites:
#'
Expand Down Expand Up @@ -59,26 +59,26 @@
#' # Create the elic_cat object for an elicitation process over 2 mechanisms of
#' # impact, 3 sites, 3 levels per sites, and a maximum number of experts per
#' # mechanism of 8.
#' my_elicit <- elic_cat_start(levels = c("Level_1", "Level_2", "Level_3"),
#' sites = c("Site_1", "Site_2", "Site_3"),
#' experts = 8,
#' mechanisms = c("mechanism_1","mechanism_2"))
#' my_elicit <- cat_start(levels = c("Level_1", "Level_2", "Level_3"),
#' sites = c("Site_1", "Site_2", "Site_3"),
#' experts = 8,
#' mechanisms = c("mechanism_1","mechanism_2"))
#' my_elicit
#'
#' # A title can be added to bind a name to the object:
#' my_elicit <- elic_cat_start(levels = c("Level_1", "Level_2", "Level_3"),
#' sites = c("Site_1", "Site_2", "Site_3"),
#' experts = 8,
#' mechanisms = c("mechanism_1","mechanism_2"),
#' title = "My elicitation")
#' my_elicit <- cat_start(levels = c("Level_1", "Level_2", "Level_3"),
#' sites = c("Site_1", "Site_2", "Site_3"),
#' experts = 8,
#' mechanisms = c("mechanism_1","mechanism_2"),
#' title = "My elicitation")
#' my_elicit
elic_cat_start <- function(levels,
sites,
experts,
mechanisms,
...,
title = "Elicitation",
verbose = TRUE) {
cat_start <- function(levels,
sites,
experts,
mechanisms,
...,
title = "Elicitation",
verbose = TRUE) {

# Check that levels, sites, and mechanisms are character vectors
check_is_character(levels, "levels")
Expand Down Expand Up @@ -120,7 +120,7 @@ check_is_character <- function(x, arg_name) {
{.cls {class(x)}}."
cli::cli_abort(c("Invalid value for {.arg {arg_name}}:",
"x" = error,
"i" = "See {.fn elicitr::elic_cat_start}."),
"i" = "See {.fn elicitr::cat_start}."),
call = rlang::caller_env())
}
}
Loading
Loading