From 004bb280883127e18ee8f438f8424bb24feabd2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Mon, 9 Nov 2020 06:31:50 +0100 Subject: [PATCH 1/2] Use dir.exists() --- R/has-file.R | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/R/has-file.R b/R/has-file.R index 5cfff567..191aec05 100644 --- a/R/has-file.R +++ b/R/has-file.R @@ -19,10 +19,7 @@ has_file <- function(filepath, contents = NULL, n = -1L) { testfun <- eval(bquote(function(path) { testfile <- file.path(path, .(filepath)) - if (!file.exists(testfile)) { - return(FALSE) - } - if (is_dir(testfile)) { + if (dir.exists(testfile)) { return(FALSE) } match_contents(testfile, .(contents), .(n)) @@ -52,10 +49,7 @@ has_dir <- function(filepath) { testfun <- eval(bquote(function(path) { testfile <- file.path(path, .(filepath)) - if (!file.exists(testfile)) { - return(FALSE) - } - is_dir(testfile) + dir.exists(testfile) })) desc <- paste0("contains a directory `", filepath, "`") @@ -262,15 +256,11 @@ str.root_criteria <- function(object, ...) { list_files <- function(path, filename) { files <- dir(path = path, pattern = filename, all.files = TRUE, full.names = TRUE) - dirs <- is_dir(files) + dirs <- dir.exists(files) files <- files[!dirs] files } -is_dir <- function(x) { - dir.exists(x) -} - match_contents <- function(f, contents, n) { if (is.null(contents)) { return(TRUE) From 28d35daa63d457f5d3ff0d5b71acf16cf6bb5669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Mon, 9 Nov 2020 06:42:37 +0100 Subject: [PATCH 2/2] Oops --- R/has-file.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/has-file.R b/R/has-file.R index 191aec05..b906d532 100644 --- a/R/has-file.R +++ b/R/has-file.R @@ -19,6 +19,9 @@ has_file <- function(filepath, contents = NULL, n = -1L) { testfun <- eval(bquote(function(path) { testfile <- file.path(path, .(filepath)) + if (!file.exists(testfile)) { + return(FALSE) + } if (dir.exists(testfile)) { return(FALSE) }