diff --git a/r/dependencies.r b/r/dependencies.r index 55eca24..97e1072 100644 --- a/r/dependencies.r +++ b/r/dependencies.r @@ -16,6 +16,7 @@ libs <- load_libs('dplyr', 'parallel', 'raster', 'rslurm', + 'R.utils', lib.loc = lib.loc) # Load permute fortran dll for footprint matrix permutation diff --git a/r/src/link_files.r b/r/src/link_files.r index d728faf..61851ac 100644 --- a/r/src/link_files.r +++ b/r/src/link_files.r @@ -1,5 +1,5 @@ -#' link_files symlinks files in exe/* to the target path -#' @author Ben Fasoli +#' link_files symlinks files to the target path using relative paths +#' @author Ben Fasoli & James Mineau #' #' @param from location of files #' @param to location to create links @@ -7,6 +7,16 @@ #' @export link_files <- function(from, to) { - files <- dir(from, full.names = T) - suppressWarnings(file.symlink(files, to)) + require(R.utils) + + # # Get all files in `from` + x <- lapply(from, list.files, full.names = T) + is_file <- sapply(x, function(x) length(x) == 0) + files <- c(from[is_file], unlist(x[!is_file])) + + # Convert to paths relative to stilt_wd + relative_files <- R.utils::getRelativePath(files, to) + + # Create the links + suppressWarnings(file.symlink(relative_files, to)) } diff --git a/r/src/simulation_step.r b/r/src/simulation_step.r index e147ad8..425874a 100644 --- a/r/src/simulation_step.r +++ b/r/src/simulation_step.r @@ -330,9 +330,7 @@ simulation_step <- function(before_footprint = list(function() {output}), # Save output object to compressed rds file and symlink to out/particles saveRDS(output, output$file) - - link <- file.path(output_wd, 'particles', basename(output$file)) - suppressWarnings(file.symlink(output$file, link)) + link_files(output$file, file.path(output_wd, 'particles')) } else { # If user opted to recycle existing trajectory files, read in the recycled @@ -381,8 +379,7 @@ simulation_step <- function(before_footprint = list(function() {output}), } # Symlink footprint to out/footprints - link <- file.path(output_wd, 'footprints', basename(foot_file)) - suppressWarnings(file.symlink(foot_file, link)) + link_files(foot_file, file.path(output_wd, 'footprints')) return(foot) })