Skip to content
Open
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
2 changes: 1 addition & 1 deletion R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build_package <- function(path, tmpdir, build_args, libpath, quiet) {
dir.create(tmpdir, recursive = TRUE, showWarnings = FALSE)
tmpdir <- normalizePath(tmpdir)

if (file.info(path)$isdir) {
if (safecheck_isdir(path)) {
if (!quiet) cat_head("R CMD build")

desc <- desc(path)
Expand Down
2 changes: 1 addition & 1 deletion R/env.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ load_env <- function(path, targz, package, envir = parent.frame()) {
if (!should_load) return()

env <- NULL
if (file.info(path)$isdir) {
if (safecheck_isdir(path)) {
env_path <- file.path(path, "tools", "check.env")
} else {
dir.create(tmp <- tempfile())
Expand Down
2 changes: 1 addition & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ rcmdcheck <- function(

error_on <- match.arg(error_on, c("never", "error", "warning", "note"))

if (file.info(path)$isdir) {
if (safecheck_isdir(path)) {
path <- find_package_root_file(path = path)
} else {
path <- normalizePath(path)
Expand Down
7 changes: 7 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,10 @@ data_literal <- function(...) {
colClasses = "character"
)
}

safecheck_isdir <- function(path){
if(!file.exists(path)) stop("path '", path, "' does not exist!")
res <- file.info(path, extra_cols = FALSE)
if(is.na(res$isdir)) stop("path '", path, "' is not readable!")
res$isdir
}
4 changes: 4 additions & 0 deletions tests/testthat/test-errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ test_that("error_on argument", {
tryCatch(rcmdcheck(), error = function(e) e)
expect_equal(value, "note")
})

test_that("error correctly when reading invalid files", {
expect_error(rcmdcheck("Invalid file name"), "path 'Invalid file name' does not exist!")
})
Loading