Skip to content

Commit f8f662b

Browse files
committed
use sans_ext() and file_ext() in xfun instead of tools, because we should allow trailing ~ or # in file extensions: yihui/xfun@1f59942
1 parent 71a5d12 commit f8f662b

File tree

9 files changed

+26
-26
lines changed

9 files changed

+26
-26
lines changed

R/draft.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ draft <- function(file,
9292
if (create_dir) {
9393

9494
# remove .Rmd extension if necessary
95-
file <- tools::file_path_sans_ext(file)
95+
file <- xfun::sans_ext(file)
9696

9797
# create dir (new dir only)
9898
if (dir_exists(file))
@@ -104,7 +104,7 @@ draft <- function(file,
104104
}
105105

106106
# Ensure we have an Rmd extension
107-
if (!identical(tolower(tools::file_ext(file)), "rmd"))
107+
if (!identical(tolower(xfun::file_ext(file)), "rmd"))
108108
file <- paste(file, ".Rmd", sep = "")
109109

110110
# Ensure the file doesn't already exist

R/html_resource_copy.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ copy_html_resources <- function(html_str, lib_dir, output_dir) {
1313
# if the resource is a CSS file, perform a similar rewriting of its
1414
# content in the library directory
1515
res_path <- file.path(output_dir, res_src)
16-
if (identical(tolower(tools::file_ext(res_path)), "css") &&
16+
if (identical(tolower(xfun::file_ext(res_path)), "css") &&
1717
file.exists(res_path)) {
1818
css_content <- copy_resources(
1919
file_string(res_path), lib_dir, lib_dir, call_css_resource_attrs

R/html_resources.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
find_external_resources <- function(input_file, encoding = 'UTF-8') {
5454

5555
# ensure we're working with valid input
56-
ext <- tolower(tools::file_ext(input_file))
56+
ext <- tolower(xfun::file_ext(input_file))
5757
if (!(ext %in% c("md", "rmd", "html", "htm", "r", "css"))) {
5858
stop("Resource discovery is only supported for R Markdown files or HTML files.")
5959
}
@@ -78,7 +78,7 @@ find_external_resources <- function(input_file, encoding = 'UTF-8') {
7878
file.exists(file.path(input_dir, path))))
7979
return(FALSE)
8080

81-
ext <- tolower(tools::file_ext(file.path(input_dir, path)))
81+
ext <- tolower(xfun::file_ext(file.path(input_dir, path)))
8282

8383
if (identical(ext, "r")) {
8484
# if this is a .R script, look for resources it contains, too
@@ -299,7 +299,7 @@ discover_rmd_resources <- function(rmd_file, discover_single_resource) {
299299
}
300300

301301
# check for knitr child documents in R Markdown documents
302-
if (tolower(tools::file_ext(rmd_file)) == "rmd") {
302+
if (tolower(xfun::file_ext(rmd_file)) == "rmd") {
303303
chunk_lines <- gregexpr(knitr::all_patterns$md$chunk.begin, rmd_content, perl = TRUE)
304304
for (idx in seq_along(chunk_lines)) {
305305
chunk_line <- chunk_lines[idx][[1]]
@@ -351,7 +351,7 @@ discover_rmd_resources <- function(rmd_file, discover_single_resource) {
351351
discover_html_resources(html_file, discover_single_resource)
352352

353353
# if this is an R Markdown file, purl the file to extract just the R code
354-
if (tolower(tools::file_ext(rmd_file)) == "rmd") {
354+
if (tolower(xfun::file_ext(rmd_file)) == "rmd") {
355355
r_file <- tempfile(fileext = ".R")
356356
# suppress possible try() errors https://github.com/rstudio/rmarkdown/issues/1247
357357
try_file <- tempfile()
@@ -443,7 +443,7 @@ discover_css_resources <- function(css_file, discover_single_resource) {
443443

444444
# given a filename, return true if the file appears to be a web file
445445
is_web_file <- function(filename) {
446-
tolower(tools::file_ext(filename)) %in% c(
446+
tolower(xfun::file_ext(filename)) %in% c(
447447
"css", "gif", "htm", "html", "jpeg", "jpg", "js", "mp3", "mp4", "png", "wav"
448448
)
449449
}

R/ioslides_presentation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ ioslides_presentation <- function(number_sections = FALSE,
318318
logo_path <- logo
319319
if (!self_contained) {
320320
# use same extension as specified logo (default is png if unspecified)
321-
logo_ext <- tools::file_ext(logo)
321+
logo_ext <- xfun::file_ext(logo)
322322
if (nchar(logo_ext) < 1)
323323
logo_ext <- "png"
324324
logo_path <- file.path(files_dir, paste("logo", logo_ext, sep = "."))

R/output_format.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ enumerate_output_formats <- function(input, envir, encoding, output_yaml = NULL)
612612
input_lines <- read_utf8(input)
613613

614614
# if this is an R file then spin it
615-
if (identical(tolower(tools::file_ext(input)), "r"))
615+
if (identical(tolower(xfun::file_ext(input)), "r"))
616616
input_lines <- knitr::spin(text = input_lines, knit = FALSE)
617617

618618
# parse _site.yml output format if we have it

R/render.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ render <- function(input,
342342
}
343343

344344
# check whether this document requires a knit
345-
requires_knit <- tolower(tools::file_ext(input)) %in% c("r", "rmd", "rmarkdown")
345+
requires_knit <- tolower(xfun::file_ext(input)) %in% c("r", "rmd", "rmarkdown")
346346

347347
# remember the name of the original input document (we overwrite 'input' once
348348
# we've knitted)
@@ -395,10 +395,10 @@ render <- function(input,
395395
intermediates <- c(intermediates, utf8_input)
396396

397397
# track whether this was straight markdown input (to prevent keep_md later)
398-
md_input <- identical(tolower(tools::file_ext(input)), "md")
398+
md_input <- identical(tolower(xfun::file_ext(input)), "md")
399399

400400
# if this is an R script then spin it first
401-
if (identical(tolower(tools::file_ext(input)), "r")) {
401+
if (identical(tolower(xfun::file_ext(input)), "r")) {
402402
# make a copy of the file to spin
403403
spin_input <- intermediates_loc(file_with_meta_ext(input, "spin", "R"))
404404
file.copy(input, spin_input, overwrite = TRUE)
@@ -768,7 +768,7 @@ render <- function(input,
768768

769769
# if this isn't html and there are html dependencies then flag an error
770770
if (!(is_pandoc_to_html(output_format$pandoc) ||
771-
identical(tolower(tools::file_ext(output_file)), "html"))) {
771+
identical(tolower(xfun::file_ext(output_file)), "html"))) {
772772
if (has_html_dependencies(knit_meta)) {
773773
if (!isTRUE(front_matter$always_allow_html)) {
774774
stop("Functions that produce HTML output found in document targeting ",
@@ -900,7 +900,7 @@ render <- function(input,
900900
# render to temporary file (preserve extension)
901901
# this also ensures we don't pass a file path with invalid
902902
# characters to our pandoc invocation
903-
file_ext <- tools::file_ext(output)
903+
file_ext <- xfun::file_ext(output)
904904
ext <- if (nzchar(file_ext))
905905
paste(".", file_ext, sep = "")
906906
else

R/shiny.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ rmarkdown_shiny_ui <- function(dir, file) {
312312
}
313313

314314
# request must be for an R Markdown or HTML document
315-
ext <- tolower(tools::file_ext(req_path))
315+
ext <- tolower(xfun::file_ext(req_path))
316316
if (!(ext %in% c("rmd", "htm", "html"))) return(NULL)
317317

318318
# document must exist
@@ -378,7 +378,7 @@ rmd_cached_output <- function(input) {
378378
resource_folder <- ""
379379

380380
# if the file is raw HTML, return it directly
381-
if (tolower(tools::file_ext(input)) %in% c("htm", "html")) {
381+
if (tolower(xfun::file_ext(input)) %in% c("htm", "html")) {
382382
return(list(
383383
cacheable = TRUE,
384384
cached = TRUE,

R/shiny_prerendered.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ shiny_prerendered_append_context <- function(con, name, code) {
612612

613613
# Prerendred data_dir for a given Rmd input file
614614
shiny_prerendered_data_dir <- function(input, create = FALSE) {
615-
data_dir <- paste0(tools::file_path_sans_ext(input), "_data")
615+
data_dir <- paste0(xfun::sans_ext(input), "_data")
616616
if (create && !dir_exists(data_dir))
617617
dir.create(data_dir)
618618
data_dir

R/util.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ is_osx <- function() {
2020
pandoc_output_file <- function(input, pandoc_options) {
2121
to <- strsplit(pandoc_options$to, "[+-]")[[1]][[1]]
2222
ext <- pandoc_output_ext(pandoc_options$ext, to, input)
23-
output <- paste0(tools::file_path_sans_ext(input), ext)
23+
output <- paste0(xfun::sans_ext(input), ext)
2424
basename(output)
2525
}
2626

@@ -29,7 +29,7 @@ pandoc_output_ext <- function(ext, to, input) {
2929
if (to %in% c("latex", "beamer")) return(".pdf")
3030
if (to %in% c("html", "html4", "html5", "s5", "slidy", "slideous", "dzslides", "revealjs"))
3131
return(".html")
32-
if (to == "markdown" && tolower(tools::file_ext(input)) != "md") return(".md")
32+
if (to == "markdown" && tolower(xfun::file_ext(input)) != "md") return(".md")
3333
paste0(".", to)
3434
}
3535

@@ -148,25 +148,25 @@ dir_exists <- function(x) {
148148
}
149149

150150
file_with_ext <- function(file, ext) {
151-
paste(tools::file_path_sans_ext(file), ".", ext, sep = "")
151+
paste(xfun::sans_ext(file), ".", ext, sep = "")
152152
}
153153

154154

155-
file_with_meta_ext <- function(file, meta_ext, ext = tools::file_ext(file)) {
156-
paste(tools::file_path_sans_ext(file),
155+
file_with_meta_ext <- function(file, meta_ext, ext = xfun::file_ext(file)) {
156+
paste(xfun::sans_ext(file),
157157
".", meta_ext, ".", ext, sep = "")
158158
}
159159

160160
knitr_files_dir <- function(file) {
161-
paste(tools::file_path_sans_ext(file), "_files", sep = "")
161+
paste(xfun::sans_ext(file), "_files", sep = "")
162162
}
163163

164164
knitr_root_cache_dir <- function(file) {
165-
paste(tools::file_path_sans_ext(file), "_cache", sep = "")
165+
paste(xfun::sans_ext(file), "_cache", sep = "")
166166
}
167167

168168
knitr_cache_dir <- function(file, pandoc_to) {
169-
paste(tools::file_path_sans_ext(file), "_cache/", pandoc_to, "/", sep = "")
169+
paste(xfun::sans_ext(file), "_cache/", pandoc_to, "/", sep = "")
170170
}
171171

172172
get_knitr_hook_list <- function(hook_names = NULL) {

0 commit comments

Comments
 (0)