generated from neurogenomics/templateR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalise all input paths before passing to rmarkdown::render()
- Loading branch information
Showing
7 changed files
with
75 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' Apply \code{\link[base]{normalizePath}} to a list of paths | ||
#' | ||
#' @param path_list A list of paths. | ||
#' | ||
#' @return A list of normalised paths or the input as is if contents are not | ||
#' a character. | ||
#' | ||
#' @keywords internal | ||
normalise_paths <- function(path_list) { | ||
if (all(is.null(path_list))) return(path_list) | ||
|
||
## Convert objects to list if not already | ||
if (!is.list(path_list) &&(!is.vector(path_list) || length(path_list) == 1)) | ||
path_list <- list(path_list) | ||
|
||
## Return input as is if not character | ||
if (!all(sapply(path_list, is.character))) return(path_list) | ||
|
||
## Normalise paths | ||
lapply(path_list, function(path) { | ||
normalizePath(path) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
test_that("normalise_paths works", { | ||
expect_null(normalise_paths(NULL)) | ||
|
||
## Return non-character items as-is | ||
data("CTCF_ChIP_peaks", package = "MotifPeeker") | ||
expect_equal(normalise_paths(CTCF_ChIP_peaks)[[1]], CTCF_ChIP_peaks) | ||
|
||
## Return full paths from relative paths | ||
file <- system.file("extdata", "CTCF_ChIP_alignment.bam", | ||
package = "MotifPeeker") | ||
expect_equal(normalise_paths(file)[[1]], file) | ||
}) |