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

use stop2() from knitr internal instead of stop(..., call. = FALSE) #2152

Merged
merged 1 commit into from
Jun 1, 2021
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
6 changes: 3 additions & 3 deletions R/context_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ context_document <- function(toc = FALSE,
sys_context <- if (is.null(context_path)) find_program("context") else context_path
ext <- match.arg(ext)
if (identical(ext, ".pdf") && !nzchar(sys_context))
stop("Cannot find ConTeXt.\n",
stop2("Cannot find ConTeXt.\n",
"Please, check that ConTeXt is installed.\n",
"For more information, see the help page '?context_document'.",
call. = FALSE)
"For more information, see the help page '?context_document'."
)

# base pandoc options for all ConTeXt output
args <- c("--standalone")
Expand Down
18 changes: 9 additions & 9 deletions R/html_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ resolve_theme <- function(theme) {
# Bootstrap/Bootswatch 3 names (backwards-compatibility)
if (is.character(theme)) {
if (length(theme) != 1) {
stop("`theme` must be character vector of length 1.", call. = FALSE)
stop2("`theme` must be character vector of length 1.")
}
if (theme %in% c("bootstrap", "default")) {
return("bootstrap")
Expand All @@ -100,17 +100,17 @@ resolve_theme <- function(theme) {
}
if (is.list(theme)) {
if (!is_available("bslib")) {
stop("Providing a list to `theme` requires the bslib package.", call. = FALSE)
stop2("Providing a list to `theme` requires the bslib package.")
}
return(as_bs_theme(theme))
}
stop(
stop2(
"`theme` expects any one of the following values: \n",
" (1) NULL (no Bootstrap), \n",
" (2) a character string referencing a Bootswatch 3 theme name, \n",
" (3) a list of arguments to bslib::bs_theme(), \n",
" (4) a bslib::bs_theme() object."
, call. = FALSE)
)
}

# At the moment, theme may be either NULL (no Bootstrap), a string (Bootswatch
Expand Down Expand Up @@ -335,25 +335,25 @@ validate_html_dependency <- function(list) {

# ensure it's the right class
if (!is_html_dependency(list))
stop("passed object is not of class html_dependency", call. = FALSE)
stop2("passed object is not of class html_dependency")

# validate required fields
if (is.null(list$name))
stop("name for html_dependency not provided", call. = FALSE)
stop2("name for html_dependency not provided")
if (is.null(list$version))
stop("version for html_dependency not provided", call. = FALSE)
stop2("version for html_dependency not provided")
list <- fix_html_dependency(list)

# check src path or href are given
if (is.null(list$src)) {
stop("src for html_dependency not provided", call. = FALSE)
stop2("src for html_dependency not provided")
}
if (!is.null(list$src$file)) {
file <- list$src$file
if (!is.null(list$package))
file <- system.file(file, package = list$package)
if (!file.exists(file)) {
stop("path for html_dependency not found: ", file, call. = FALSE)
stop2("path for html_dependency not found: ", file)
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/html_document_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ html_document_base <- function(theme = NULL,
for (f in css) {
if (grepl("\\.s[ac]ss$", f)) {
if (!xfun::loadable("sass")) {
stop("Using `.sass` or `.scss` file in `css` argument requires the sass package.", call. = FALSE)
stop2("Using `.sass` or `.scss` file in `css` argument requires the sass package.")
}
f <- sass::sass(
sass::sass_file(f),
Expand Down
9 changes: 3 additions & 6 deletions R/html_notebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,13 @@ validate_output_source <- function(output_source) {
error_msg <- sprintf("%s '%s'", prefix, required_signature)

# ensure function
if (!is.function(output_source))
stop(error_msg, call. = FALSE)
if (!is.function(output_source)) stop2(error_msg)

# check formals
fmls <- names(formals(output_source))
if (length(fmls) < 3)
stop(error_msg, call. = FALSE)
if (length(fmls) < 3) stop2(error_msg)

if (!("..." %in% fmls))
stop(error_msg, call. = FALSE)
if (!("..." %in% fmls)) stop2(error_msg)

TRUE
}
6 changes: 3 additions & 3 deletions R/ioslides_presentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ ioslides_presentation <- function(number_sections = FALSE,
"faster" = "0.2",
"slower" = "0.6")
else
stop('transition must be "default", "faster", "slower" or a ',
'numeric value (representing seconds)', call. = FALSE)
stop2('transition must be "default", "faster", "slower" or a ',
'numeric value (representing seconds)')
args <- c(args, pandoc_variable_arg("transition", transition))

# additional css
Expand Down Expand Up @@ -432,7 +432,7 @@ ioslides_presentation <- function(number_sections = FALSE,
output_lines <- c(preface_lines, slides_lines, suffix_lines)
write_utf8(output_lines, output_file)
} else {
stop("Slides placeholder not found in slides HTML", call. = FALSE)
stop2("Slides placeholder not found in slides HTML")
}

output_file
Expand Down
4 changes: 2 additions & 2 deletions R/latex_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ validate_latex_dependency <- function(list) {

# ensure it's the right class
if (!is_latex_dependency(list))
stop("passed object is not of class latex_dependency", call. = FALSE)
stop2("passed object is not of class latex_dependency")

# validate required fields
if (is.null(list$name))
stop("name (package name) for latex_dependency not provided", call. = FALSE)
stop2("name (package name) for latex_dependency not provided")
list
}

Expand Down
10 changes: 5 additions & 5 deletions R/output_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ output_format_from_yaml_front_matter <- function(input_lines,

# ensure input is the correct data type
if (!is_null_or_string(format_name)) {
stop("Unrecognized output format specified", call. = FALSE)
stop2("Unrecognized output format specified")
}

# parse the yaml
Expand Down Expand Up @@ -586,7 +586,7 @@ create_output_format <- function(name,

# validate the name
if (is.null(name))
stop("The output format name must not be NULL", call. = FALSE)
stop2("The output format name must not be NULL")
if (name == "revealjs_presentation")
stop("reveal.js presentations are now located in a separate package: ",
"https://github.com/jjallaire/revealjs")
Expand All @@ -597,7 +597,7 @@ create_output_format <- function(name,
# call the function
output_format <- do.call(output_format_func, options)
if (!is_output_format(output_format))
stop("Format is not of class rmarkdown_output_format", call. = FALSE)
stop2("Format is not of class rmarkdown_output_format")

# return the format
output_format
Expand All @@ -617,7 +617,7 @@ output_format_string_from_ext <- function(output_file) {
create_output_format_function <- function(name) {
output_format_func <- eval(xfun::parse_only(name))
if (!is.function(output_format_func))
stop("YAML output format must evaluate to a function", call. = FALSE)
stop2("YAML output format must evaluate to a function")
output_format_func
}

Expand Down Expand Up @@ -719,7 +719,7 @@ parse_yaml_front_matter <- function(input_lines) {
validate_front_matter <- function(front_matter) {
front_matter <- trim_trailing_ws(front_matter)
if (grepl(":$", front_matter))
stop("Invalid YAML front matter (ends with ':')", call. = FALSE)
stop2("Invalid YAML front matter (ends with ':')")
}


Expand Down
8 changes: 4 additions & 4 deletions R/pandoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pandoc_convert <- function(input,
result <- system(command)
})
if (result != 0)
stop("pandoc document conversion failed with error ", result, call. = FALSE)
stop2("pandoc document conversion failed with error ", result)

invisible(NULL)
}
Expand Down Expand Up @@ -207,7 +207,7 @@ pandoc_available <- function(version = NULL,
"pandoc", if (!is.null(version)) c("version", version, "or higher"),
"is required and was not found (see the help page ?rmarkdown::pandoc_available)."
)
if (error && !found) stop(paste(msg, collapse = " "), call. = FALSE)
if (error && !found) stop2(paste(msg, collapse = " "))

found
}
Expand Down Expand Up @@ -473,8 +473,8 @@ pandoc_self_contained_html <- function(input, output) {
validate_self_contained <- function(mathjax) {

if (identical(mathjax, "local"))
stop("Local MathJax isn't compatible with self_contained\n",
"(you should set self_contained to FALSE)", call. = FALSE)
stop2("Local MathJax isn't compatible with self_contained\n",
"(you should set self_contained to FALSE)")
}

pandoc_mathjax_args <- function(mathjax,
Expand Down
25 changes: 12 additions & 13 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,10 @@ render <- function(input,
file_name_without_shell_chars(basename(input)))

if (file.exists(input_no_shell_chars)) {
stop("The name of the input file cannot contain the special shell ",
stop2("The name of the input file cannot contain the special shell ",
"characters: ", .shell_chars_regex, " (attempted to copy to a ",
"version without those characters '", input_no_shell_chars, "' ",
"however that file already exists)", call. = FALSE)
"however that file already exists)")
}
file.copy(input, input_no_shell_chars, overwrite = TRUE)
intermediates <- c(intermediates, input_no_shell_chars)
Expand Down Expand Up @@ -497,8 +497,7 @@ render <- function(input,

# Stop the render process early if the output directory does not exist
if (!dir_exists(output_dir)) {
stop("The directory '", output_dir, "' does not not exist.",
call. = FALSE)
stop2("The directory '", output_dir, "' does not not exist.")
}

# use output filename based files dir
Expand Down Expand Up @@ -723,8 +722,8 @@ render <- function(input,
inherits(envirParams, "knit_param")

if (!isKnownParamsObject) {
stop("params object already exists in knit environment ",
"so can't be overwritten by render params", call. = FALSE)
stop2("params object already exists in knit environment ",
"so can't be overwritten by render params")
}
}

Expand Down Expand Up @@ -788,20 +787,20 @@ render <- function(input,
identical(tolower(xfun::file_ext(output_file)), "html"))) {
if (has_html_dependencies(knit_meta)) {
if (!isTRUE(front_matter$always_allow_html)) {
stop("Functions that produce HTML output found in document targeting ",
stop2("Functions that produce HTML output found in document targeting ",
pandoc_to, " output.\nPlease change the output type ",
"of this document to HTML. Alternatively, you can allow\n",
"HTML output in non-HTML formats by adding this option to the YAML front",
"-matter of\nyour rmarkdown file:\n\n",
" always_allow_html: true\n\n",
"Note however that the HTML output will not be visible in non-HTML formats.\n\n",
call. = FALSE)
"Note however that the HTML output will not be visible in non-HTML formats.\n\n"
)
}
}
if (!identical(runtime, "static")) {
stop("Runtime '", runtime, "' is not supported for ",
stop2("Runtime '", runtime, "' is not supported for ",
pandoc_to, " output.\nPlease change the output type ",
"of this document to HTML.", call. = FALSE)
"of this document to HTML.")
}
}

Expand Down Expand Up @@ -1157,8 +1156,8 @@ resolve_df_print <- function(df_print) {
else if (df_print == "default")
df_print <- print
else
stop('Invalid value for df_print (valid values are ',
paste(valid_methods, collapse = ", "), call. = FALSE)
stop2('Invalid value for df_print (valid values are ',
paste(valid_methods, collapse = ", "))
}

df_print
Expand Down
6 changes: 3 additions & 3 deletions R/render_site.R
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,9 @@ input_as_dir <- function(input) {
# ensure the input dir exists
if (!file.exists(input)) {
input <- normalize_path(input, mustWork = FALSE)
if (!file.exists(input)) stop(
"The specified directory '", input, "' does not exist.", call. = FALSE
)
if (!file.exists(input)) {
stop2("The specified directory '", input, "' does not exist.")
}
}

# convert from file to directory if necessary
Expand Down
9 changes: 4 additions & 5 deletions R/shiny_prerendered.R
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ shiny_prerendered_chunk <- function(context, code, singleton = FALSE) {

# verify we are in runtime: shiny_prerendered
if (!is_shiny_prerendered(knitr::opts_knit$get("rmarkdown.runtime")))
stop("The shiny_prerendered_chunk function can only be called from ",
"within runtime: shinyrmd",
call. = FALSE)
stop2("The shiny_prerendered_chunk function can only be called from ",
"within runtime: shinyrmd"
)

# add the prerendered chunk to knit_meta
knitr::knit_meta_add(list(
Expand Down Expand Up @@ -613,8 +613,7 @@ shiny_prerendered_append_contexts <- function(runtime, file) {

# validate we are in runtime: shiny_prerendered
if (!is_shiny_prerendered(runtime)) {
stop("The code within this document requires runtime: shinyrmd",
call. = FALSE)
stop2("The code within this document requires runtime: shinyrmd")
}

# open the file
Expand Down
6 changes: 4 additions & 2 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ trim_trailing_ws <- function(x) {
base_dir <- function(x) {
base <- unique(dirname(x))
if (length(base) > 1) {
stop("Input files not all in same directory, please supply explicit wd",
call. = FALSE)
stop2("Input files not all in same directory, please supply explicit wd")
}
base
}
Expand Down Expand Up @@ -562,6 +561,9 @@ get_loaded_packages <- function() {
)
}

warning2 = function(...) warning(..., call. = FALSE)
stop2 = function(...) stop(..., call. = FALSE)

# devtools metadata -------------------------------------------------------

# from pkgdown
Expand Down