Skip to content

Commit d6ca54e

Browse files
committed
Write to temp.dir by default to comply with CRAN
1 parent cfd2dbf commit d6ca54e

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

R/mummer_alignment.R

+22-15
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#' view all filtering options, run `delta-filter --help` in the terminal.
2222
#' @param remove_files Logical indicating whether to remove intermediate files
2323
#' generated during the process, defaults to TRUE.
24-
#' @param output_dir Optional directory to save output files; defaults to NULL,
25-
#' which uses the input file directory for outputs.
24+
#' @param output_dir Optional directory for output files; defaults to
25+
#' \code{tempdir()}
2626
#'
2727
#' @return A data frame combining all alignment results, or NULL if errors occur
2828
#' during processing.
@@ -59,31 +59,30 @@ mummer_alignment <- function(
5959
mummer_options = "",
6060
filter_options = "",
6161
remove_files = TRUE,
62-
output_dir = NULL
62+
output_dir = tempdir()
6363
){
6464

6565
if (!dir.exists(path)) {
6666
stop("The specified directory does not exist. Please check the file path.")
6767
}
6868

69-
# Check if the file_path contains spaces
70-
if (grepl(" ", path)) {
71-
stop("MUMmer requires a directory path without spaces.")
69+
# Ensure the output directory exists
70+
if (!dir.exists(output_dir)) {
71+
dir.create(output_dir, recursive = TRUE)
7272
}
7373

74-
if (!is.null(output_dir) && !dir.exists(output_dir)) {
75-
stop("The specified output directory does not exist. Please check the file path.")
74+
if (grepl(" ", path)) {
75+
stop("MUMmer requires a directory path without spaces.")
7676
}
7777

78-
# Check if the file_path contains spaces
79-
if (!is.null(output_dir) && grepl(" ", output_dir)) {
80-
stop("MUMmer requires a output directory path without spaces.")
78+
if (grepl(" ", output_dir)) {
79+
stop("MUMmer requires an output directory path without spaces.")
8180
}
8281

8382
all_files <- list.files(path, full.names = TRUE, pattern = "\\.gbk$|\\.gb$|\\.fasta$")
8483

8584
# Move all files to the output dir if specified
86-
if(!is.null(output_dir)){
85+
if(output_dir != path){
8786
sapply(all_files, function(x) file.copy(x, output_dir, overwrite = TRUE))
8887
path <- output_dir
8988
all_files <- list.files(path, full.names = TRUE, pattern = "\\.gbk$|\\.gb$|\\.fasta$")
@@ -181,9 +180,17 @@ mummer_alignment <- function(
181180
links <- Filter(Negate(is.null), links)
182181
links <- do.call(rbind, links)
183182

184-
if (!is.null(gbk_files) && length(gbk_files) > 0 && remove_files) {
185-
remove_files <- sub("\\.gbk$|\\.gb$", ".fasta", gbk_files)
186-
file.remove(remove_files)
183+
if (remove_files) {
184+
if (output_dir == tempdir()) {
185+
186+
files_to_remove <- all_files
187+
files_to_remove <- files_to_remove[file.exists(files_to_remove)]
188+
file.remove(files_to_remove)
189+
} else if (!is.null(gbk_files) && length(gbk_files) > 0) {
190+
fasta_files_to_remove <- sub("\\.gbk$|\\.gb$", ".fasta", gbk_files)
191+
fasta_files_to_remove <- fasta_files_to_remove[file.exists(fasta_files_to_remove)]
192+
file.remove(fasta_files_to_remove)
193+
}
187194
}
188195

189196
return(links)

man/mummer_alignment.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)