Skip to content

Commit

Permalink
error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryMcCartan committed Mar 26, 2023
1 parent fd702c8 commit 2b220fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
23 changes: 17 additions & 6 deletions R/causal_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ add_causal_col <- function(data, what, ..., ptype=NULL) {
data <- as_causal_tbl(data)
dots <- enquos(...)
if (length(dots) > 1) {
cli_abort("Use {.fn set_causal_col} to add more than one column at a time")
cli_abort(c("Only one column can be added at a time.",
">"="Use {.fn set_causal_col} to add more than one column."),
call=parent.frame())
}

col <- single_col_name(dots[[1]], data, what)
Expand Down Expand Up @@ -120,7 +122,9 @@ has_outcome <- function(data) {
#' @export
pull_outcome <- function(data) {
if (!has_outcome(data)) {
cli::cli_abort("No outcome is set in {.arg data}.", call=parent.frame())
cli::cli_abort(c("No outcome is set in {.arg data}.",
">"="Use {.fn set_outcome} set an outcome variable."),
call=parent.frame())
}
data[[get_outcome(data)]]
}
Expand Down Expand Up @@ -178,7 +182,9 @@ has_treatment <- function(data) {
#' @export
pull_treatment <- function(data) {
if (!has_treatment(data)) {
cli::cli_abort("No treatment is set in {.arg data}.", call=parent.frame())
cli::cli_abort(c("No treatment is set in {.arg data}.",
">"="Use {.fn set_treatment} set an treatment variable."),
call=parent.frame())
}
data[[get_treatment(data)]]
}
Expand Down Expand Up @@ -233,19 +239,24 @@ has_panel <- function(data) {
!is.null(causal_cols(data)$panel_time)
}
#' @rdname set_panel
#' @return For `pull_panel_unit()` and `pull_panel_time()` the vector of the panel variable.
#' @return For `pull_panel_unit()` and `pull_panel_time()`, the vector of the
#' corresponding panel variable.
#' @export
pull_panel_unit <- function(data) {
if (!has_panel(data)) {
cli::cli_abort("No panel is set in {.arg data}.")
cli::cli_abort(c("No panel structure exists for {.arg data}.",
">"="Use {.fn set_panel} to set up panel data structure."),
call=parent.frame())
}
data[[get_panel(data)$unit]]
}
#' @rdname set_panel
#' @export
pull_panel_time <- function(data) {
if (!has_panel(data)) {
cli::cli_abort("No panel is set in {.arg data}.")
cli::cli_abort(c("No panel structure exists for {.arg data}.",
">"="Use {.fn set_panel} to set up panel data structure."),
call=parent.frame())
}
data[[get_panel(data)$time]]
}
Expand Down
3 changes: 2 additions & 1 deletion man/set_panel.Rd

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

0 comments on commit 2b220fd

Please sign in to comment.