Skip to content

Commit

Permalink
style: remove rlang prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed Jul 28, 2023
1 parent 43f3e75 commit 14ce6b9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
39 changes: 21 additions & 18 deletions R/add_to_body.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ add_text_to_body <- function(docx,
.null = NULL,
.envir = parent.frame(),
...) {
rlang::check_required(value)
check_required(value)
value <- glue::glue(value, .na = .na, .null = .null, .envir = .envir)
add_to_body(docx, value = value, style = style, pos = pos, ...)
}
Expand All @@ -131,7 +131,7 @@ add_xml_to_body <- function(docx,
pos = "after",
...,
call = caller_env()) {
rlang::check_required(str, call = call)
check_required(str, call = call)
add_to_body(docx, str = str, pos = pos, ..., call = call)
}

Expand Down Expand Up @@ -186,8 +186,8 @@ add_gt_to_body <- function(docx,
tablecontainer = TRUE,
...,
call = caller_env()) {
rlang::check_required(gt_object, call = call)
rlang::check_installed("gt", call = call)
check_required(gt_object, call = call)
check_installed("gt", call = call)

str <- gt::as_word(
gt_object,
Expand All @@ -199,6 +199,9 @@ add_gt_to_body <- function(docx,
)

if (!tablecontainer) {
# FIXME: I thought this worked prior to incorporating the gto code but it is
# not working any more. Check and possibly remove the tablecontainer
# parameter if I can't get it working.
docx <- add_xml_to_body(
docx,
str = str,
Expand Down Expand Up @@ -250,7 +253,7 @@ add_gg_to_body <- function(docx,
style = "Normal",
pos = "after",
...) {
rlang::check_required(value)
check_required(value)
docx <- add_to_body(docx, value = value, style = style, pos = pos, ...)

if (!is.null(caption) && !is.null(value[["labels"]][[caption]])) {
Expand Down Expand Up @@ -295,19 +298,19 @@ add_value_with_keys <- function(docx,
)

arg <- "keyword"
rlang::check_required(value)
.f <- rlang::as_function(.f)
check_required(value)
.f <- as_function(.f)

value <- set_vec_value_names(value, arg = arg, ...)
params <- rlang::list2(...)
params <- list2(...)

if (rlang::has_name(params, arg)) {
if (has_name(params, arg)) {
params[[arg]] <- NULL
}

for (i in seq_along(value)) {
docx <-
rlang::exec(
exec(
.f,
docx,
value = value[[i]],
Expand All @@ -334,19 +337,19 @@ add_str_with_keys <- function(docx,
)

arg <- "keyword"
rlang::check_required(str)
.f <- rlang::as_function(.f)
check_required(str)
.f <- as_function(.f)

str <- set_vec_value_names(str, arg = arg, ...)
params <- rlang::list2(...)
params <- list2(...)

if (rlang::has_name(params, arg)) {
if (has_name(params, arg)) {
params[[arg]] <- NULL
}

for (i in seq_along(str)) {
docx <-
rlang::exec(
exec(
.f,
docx,
str = str[[i]],
Expand All @@ -368,12 +371,12 @@ add_str_with_keys <- function(docx,
#' @importFrom rlang is_named list2 set_names
#' @importFrom cli cli_abort
set_vec_value_names <- function(value, nm = NULL, arg = "keyword", ...) {
if (rlang::is_named(value)) {
if (is_named(value)) {
return(value)
}

if (is.null(nm)) {
params <- rlang::list2(...)
params <- list2(...)
if (is.null(params[[arg]]) || (length(params[[arg]]) != length(value))) {
cli_abort(
"{.arg value} must {.arg {arg}} must be be the same length
Expand All @@ -383,5 +386,5 @@ set_vec_value_names <- function(value, nm = NULL, arg = "keyword", ...) {
nm <- params[[arg]]
}

rlang::set_names(value, nm)
set_names(value, nm)
}
3 changes: 1 addition & 2 deletions R/convert_docx.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ convert_docx <- function(docx = NULL,
overwrite = TRUE,
quiet = TRUE,
...) {
rlang::check_installed("rmarkdown")
check_installed("rmarkdown")

if (is_officer(docx, "rdocx")) {
if (!is.null(input) && is_true(quiet)) {
Expand All @@ -72,7 +72,6 @@ convert_docx <- function(docx = NULL,

path <- path %||% getwd()
} else if (is.null(input)) {
rlang::check_required(docx)
check_docx_fileext(docx)
input <- docx
}
Expand Down
2 changes: 1 addition & 1 deletion R/officer_media.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ officer_media <- function(filename = NULL,

if (isTRUE(list)) {
cli::cli_bullets(
rlang::set_names(
set_names(
basename(media_files),
rep("*", length(media_files))
)
Expand Down
4 changes: 2 additions & 2 deletions R/officer_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ is_officer_summary <- function(x,

nm_check <- TRUE
if (identical(summary_type, "doc")) {
nm_check <- any(rlang::has_name(x, c(docx_nm, pptx_nm)))
nm_check <- any(has_name(x, c(docx_nm, pptx_nm)))
}

all(rlang::has_name(x, nm)) && nm_check
all(has_name(x, nm)) && nm_check
}
12 changes: 6 additions & 6 deletions R/officer_tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ officer_tables <- function(x,
return(do.call("rbind", tables))
}

rlang::set_names(tables, nm %||% glue("doc_index_{index}"))
set_names(tables, nm %||% glue("doc_index_{index}"))
}

#' @rdname officer_tables
Expand Down Expand Up @@ -145,7 +145,7 @@ officer_table <- function(x,
body_cells <- table_cells
header_cells <- data.frame()

if (rlang::has_name(x, "is_header")) {
if (has_name(x, "is_header")) {
header_cells <- officer_table_pivot(subset_header(table_cells, TRUE))
body_cells <- subset_header(table_cells, FALSE)
}
Expand Down Expand Up @@ -189,7 +189,7 @@ officer_table <- function(x,
nm <- utils::head(body_cells, 1)

return(
rlang::set_names(
set_names(
utils::tail(body_cells, n_body_rows - 1),
nm
)
Expand All @@ -204,7 +204,7 @@ officer_table <- function(x,
body_cells[[col]] <- rep(col_value, n_body_rows)
}

return(rlang::set_names(body_cells, nm))
return(set_names(body_cells, nm))
}

list(body_cells, header_cells)
Expand All @@ -215,9 +215,9 @@ officer_table <- function(x,
#' @importFrom rlang has_name
officer_table_index <- function(x) {
tables <- subset_type(x, "table cell")
if (rlang::has_name(x, "doc_index")) {
if (has_name(x, "doc_index")) {
unique(tables[["doc_index"]])
} else if (rlang::has_name(x, "id")) {
} else if (has_name(x, "id")) {
unique(tables[["id"]])
}
}
Expand Down
10 changes: 4 additions & 6 deletions R/write_officer.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ write_officer <- function(x,
overwrite = TRUE,
modified_by = Sys.getenv("USER"),
...) {
rlang::check_required(x)
rlang::check_required(path)
check_officer(x, call = current_call())

check_officer(x, call = rlang::current_call())
check_office_fileext(
path,
fileext = c("docx", "pptx", "xlsx"),
call = rlang::current_call()
call = current_call()
)

is_xlsx <- isTRUE(is_fileext_path(path, "xlsx"))

if (isFALSE(rlang::is_empty(rlang::list2(...))) && !is_xlsx) {
if (isFALSE(is_empty(list2(...))) && !is_xlsx) {
x <-
officer::set_doc_properties(
x,
Expand All @@ -51,7 +49,7 @@ write_officer <- function(x,
file.remove(path)
}

if (!rlang::is_installed("withr")) {
if (!is_installed("withr")) {
print(x, target = path)
} else {
withr::with_envvar(
Expand Down

0 comments on commit 14ce6b9

Please sign in to comment.