-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from TanguyBarthelemy/master
Requirements for CRAN
- Loading branch information
Showing
17 changed files
with
365 additions
and
192 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
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 |
---|---|---|
@@ -1,44 +1,74 @@ | ||
#' Copy a WS | ||
#' | ||
#' @param path_ws the path to the folder containing the WS | ||
#' (the XML file + the WS folder) | ||
#' @param new_path the path to the new folder which will contains the WS | ||
#' (the XML file + the WS folder) | ||
#' @param ws_name the name of the WS | ||
#' @param from the path to the folder containing the WS (the XML file + the WS | ||
#' folder) | ||
#' @param to the path to the new folder which will contains the WS (the XML | ||
#' file + the WS folder) | ||
#' @param overwrite Overwrite existing file (Defaults to TRUE) | ||
#' @param verbose A boolean to print indications on the processing status | ||
#' (optional and TRUE by default) | ||
#' | ||
#' @return TRUE | ||
#' @export | ||
#' | ||
#' @examples | ||
#' @returns the function returns invisibly (with \code{invisible()}) a boolean | ||
#' specifying if the transfer was done or an error if the specified paths or | ||
#' workspace don't exists | ||
#' | ||
#' @examples | ||
#' # Déplacement d'un WS dans un environnement temporaire | ||
#' rjdworkspace:::copy_ws( | ||
#' destination_dir <- tempdir() | ||
#' | ||
#' # Copy of a worspace in a temporary environment | ||
#' copy_ws( | ||
#' ws_name = "ws_output", | ||
#' path_ws = file.path(system.file("extdata", package = "rjdworkspace"), "WS") | ||
#' from = file.path(system.file("extdata", package = "rjdworkspace"), "WS"), | ||
#' to = destination_dir | ||
#' ) | ||
#' | ||
copy_ws <- function(ws_name, path_ws, new_path = tempdir()) { | ||
path_ws <- normalizePath(path_ws) | ||
new_path <- normalizePath(new_path) | ||
copy_ws <- function(ws_name, | ||
from, | ||
to = tempdir(), | ||
overwrite = TRUE, | ||
verbose = TRUE) { | ||
|
||
from <- normalizePath(from, mustWork = TRUE) | ||
to <- normalizePath(to, mustWork = TRUE) | ||
|
||
dir_path <- normalizePath(file.path(path_ws, ws_name)) | ||
xml_path <- normalizePath(file.path(path_ws, paste0(ws_name, ".xml"))) | ||
from_ws_dir <- normalizePath(file.path(from, ws_name), mustWork = TRUE) | ||
from_ws_xml <- normalizePath(file.path(from, paste0(ws_name, ".xml")), mustWork = TRUE) | ||
|
||
if (!(dir.exists(dir_path) && file.exists(xml_path))) { | ||
stop("Le WS n'existe pas.") | ||
to_ws_dir <- normalizePath(file.path(to, ws_name), mustWork = FALSE) | ||
to_ws_xml <- normalizePath(file.path(to, paste0(ws_name, ".xml")), mustWork = FALSE) | ||
|
||
if ((dir.exists(to_ws_dir) && file.exists(to_ws_xml))) { | ||
message("A workspace already exists in the destination folder.") | ||
if (overwrite) { | ||
unlink(to_ws_dir, recursive = TRUE, force = TRUE) | ||
unlink(to_ws_xml, recursive = TRUE, force = TRUE) | ||
message("It will be rewritten.") | ||
} else { | ||
message("it will not be rewritten.") | ||
return(invisible(FALSE)) | ||
} | ||
} | ||
|
||
file.copy( | ||
from = dir_path, | ||
to = new_path, | ||
from = from_ws_dir, | ||
to = to, | ||
recursive = TRUE, | ||
overwrite = TRUE | ||
) | ||
file.copy( | ||
from = xml_path, | ||
to = new_path, | ||
from = from_ws_xml, | ||
to = to, | ||
recursive = TRUE, | ||
overwrite = TRUE | ||
) | ||
|
||
return(TRUE) | ||
if (verbose) { | ||
cat(" Successful copy!\n") | ||
} | ||
|
||
return(invisible(TRUE)) | ||
} |
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
Oops, something went wrong.