From 346e2ec25fe3183ab39d1055525e84fe25f68d51 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 4 Apr 2024 11:11:47 -0500 Subject: [PATCH] rename class names 'block' to 'knitr_block', and 'inline' to 'knitr_inline' since I need to export the print() methods and the names 'block' and 'inline' are too general --- NAMESPACE | 10 ++++++---- R/block.R | 8 ++++---- R/parser.R | 11 ++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 004653f04c..dd649306ae 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,11 +6,13 @@ S3method(knit_print,default) S3method(knit_print,knit_asis) S3method(knit_print,knit_asis_url) S3method(knit_print,knitr_kable) +S3method(print,knitr_block) +S3method(print,knitr_inline) S3method(print,knitr_kable) -S3method(process_group,block) -S3method(process_group,inline) -S3method(process_tangle,block) -S3method(process_tangle,inline) +S3method(process_group,knitr_block) +S3method(process_group,knitr_inline) +S3method(process_tangle,knitr_block) +S3method(process_tangle,knitr_inline) S3method(sew,character) S3method(sew,default) S3method(sew,error) diff --git a/R/block.R b/R/block.R index cdc8a6a57b..e19d83e672 100644 --- a/R/block.R +++ b/R/block.R @@ -3,9 +3,9 @@ process_group = function(x) { UseMethod('process_group', x) } #' @export -process_group.block = function(x) call_block(x) +process_group.knitr_block = function(x) call_block(x) #' @export -process_group.inline = function(x) { +process_group.knitr_inline = function(x) { x = call_inline(x) knit_hooks$get('text')(x) } @@ -588,7 +588,7 @@ process_tangle = function(x) { UseMethod('process_tangle', x) } #' @export -process_tangle.block = function(x) { +process_tangle.knitr_block = function(x) { params = opts_chunk$merge(x$params) for (o in c('purl', 'eval', 'child')) { if (inherits(try(params[o] <- list(eval_lang(params[[o]]))), 'try-error')) { @@ -615,7 +615,7 @@ process_tangle.block = function(x) { label_code(code, x) } #' @export -process_tangle.inline = function(x) { +process_tangle.knitr_inline = function(x) { output = if (opts_knit$get('documentation') == 2L) { output = paste("#'", gsub('\n', "\n#' ", x$input, fixed = TRUE)) diff --git a/R/parser.R b/R/parser.R index 281534f31e..7888d9ccf9 100644 --- a/R/parser.R +++ b/R/parser.R @@ -148,7 +148,7 @@ parse_block = function(code, header, params.src, markdown_mode = out_format('mar } } - structure(class = 'block', list( + structure(class = 'knitr_block', list( params = params, params.src = params.src, params.chunk = parts$src) ) } @@ -196,8 +196,8 @@ partition_chunk = function(engine, code) { xfun::divide_chunk(engine, code) } - -print.block = function(x, ...) { +#' @export +print.knitr_block = function(x, ...) { params = x$params if (opts_knit$get('verbose')) { code = knit_code$get(params$label) @@ -231,11 +231,12 @@ parse_inline = function(input, patterns) { structure( list(input = input, location = loc, code = code2, code.src = code1), - class = 'inline' + class = 'knitr_inline' ) } -print.inline = function(x, ...) { +#' @export +print.knitr_inline = function(x, ...) { if (opts_knit$get('verbose')) { cat('\n') if (nrow(x$location)) {