Skip to content

Commit

Permalink
remove warnings for vignette_path outside a vignette folder
Browse files Browse the repository at this point in the history
  • Loading branch information
bburns632 committed Apr 24, 2024
1 parent 05dde2c commit 48db232
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 84 deletions.
36 changes: 0 additions & 36 deletions R/CreatePackageVignette.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,42 +85,6 @@ CreatePackageVignette <- function(pkg = "."
, dirname(vignette_path)))
}

# Check if vignette_path matches the right package
# if the path is to a file in a directory named vignettes
vignetteDirAbsPath <- normalizePath(dirname(vignette_path))
# If path is a vignettes directory
if (grepl('/vignettes$', vignetteDirAbsPath)) {
# Get path for expected DESCRIPTION file for package
expectedDescriptionPath <- gsub(
pattern = "vignettes$"
, replacement = "DESCRIPTION"
, x = vignetteDirAbsPath
)

# If DESCRIPTION file exists check the name
if (file.exists(expectedDescriptionPath)) {
foundPkgName <- read.dcf(expectedDescriptionPath)[1,][["Package"]]

# If it doesn't match pkg_name, give warning
if (!identical(foundPkgName, pkg_name)) {
log_warn(glue::glue(
"You are writing a report for {pkg_name} to the vignettes "
, "directory for {foundPkgName}"
, pkg_name = pkg_name
, foundPkgName = foundPkgName))
}

# Otherwise, warn that we're writing to a vignettes folder inside
# a directory that is not a package root
} else {
log_warn(paste(
"You specified a path to a vignettes directory"
, vignetteDirAbsPath
, "that is not inside a package root directory."
))
}
}

log_info(sprintf(
"Creating pkgnet package report as vignette for %s..."
, pkg_name
Expand Down
48 changes: 0 additions & 48 deletions tests/testthat/test-CreatePackageVignette.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,51 +174,3 @@ test_that("Test that CreatePackageVignette errors for bad inputs", {
, fixed = TRUE
)
})

test_that("CreatePackageVignette warns if vignette_path seems wrong", {

pkgPath <- .CreateSourceCopy(sourcePath)
on.exit(expr = unlink(pkgPath, recursive = TRUE))

# In a vignettes directory that isn't in a package root
vignettesDir <- file.path(tempdir(), "vignettes")
dir.create(vignettesDir)
expect_warning(
CreatePackageVignette(pkg = pkgPath
, vignette_path = file.path(vignettesDir
, "pkgnet_report.Rmd")
)
, regexp = paste("not inside a package root directory")
, fixed = TRUE
)
# Clean up
unlink(file.path(tempdir(), "vignettes"), recursive = TRUE)

# If in root of a different package
suppressWarnings({
# creating a temporary environment to avoid the following error from package.skeleton()
# "... no R objects specified or available"
basketball_env <- new.env()
basketball_env[["a"]] <- function(){return(1)}
utils::package.skeleton(
name = "basketballstats"
, environment = basketball_env
, path = tempdir()
)
})
dir.create(file.path(tempdir(), "basketballstats", "vignettes"))
expect_warning(
CreatePackageVignette(pkg = pkgPath
, vignette_path = file.path(tempdir()
, "basketballstats"
, "vignettes"
, "pkgnet_report.Rmd")
)
, regexp = paste("You are writing a report for baseballstats to the"
, "vignettes directory for basketballstats")
, fixed = TRUE
)
# Clean up
unlink(file.path(tempdir(), "basketballstats"), recursive = TRUE)

})

0 comments on commit 48db232

Please sign in to comment.